2

我有一个Google电子表格,我想通过Google Python客户端读取。这个电子表格是私人的。下面是代码:使用Python客户端库读取私人Google电子表格

import gdata 
import gdata.docs 
import gdata.spreadsheet 
import gdata.spreadsheet.service 
client = gdata.spreadsheet.service.SpreadsheetsService() 
client.email = '[email protected]' 
client.password = 'yyyyy' 
client.ProgrammaticLogin() 
spreadsheet_feed = client.GetFeed('http://spreadsheets.google.com/feeds/spreadsheets/private/full') 
first_entry = spreadsheet_feed.entry[0] 
key = first_entry.id.text.rsplit('/')[-1] 
worksheets_feed = client.GetWorksheetsFeed(key) 
for entry in worksheets_feed.entry: 
    print entry.title.text 

这给了我下面的错误:

client.ProgrammaticLogin() 
    File "C:\python27\lib\site-packages\gdata\service.py", line 793, in ProgrammaticLogin 
    raise BadAuthentication, 'Incorrect username or password' 
gdata.service.BadAuthentication: Incorrect username or password 

为什么,即使用户名/密码是否正确,用户名是在公司领域,但在谷歌服务器?

回答

1

您面临的问题是因为谷歌安全协议。 Google不允许使用安全性较低的应用连接到您的帐户,而这些gdata api使用的安全措施较少,因此如果您想使用这些API连接到您的帐户,则必须启用访问您的帐户才能使用安全性较低的应用。转到此链接: https://www.google.com/settings/security/lesssecureapps