我有一个 Google 电子表格,我想通过 Google Python 客户端读取它。此电子表格是私有(private)的。这是代码:
import gdata
import gdata.docs
import gdata.spreadsheet
import gdata.spreadsheet.service
client = gdata.spreadsheet.service.SpreadsheetsService()
client.email = 'xxx.xxx@companyName.com'
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
为什么即使用户名/密码正确并且用户名在公司域中,但在 Google 服务器上?
请您参考如下方法:
您遇到的问题是因为谷歌安全协议(protocol)。 Google 不允许任何安全性较低的应用程序连接到您的帐户,并且这些 gdata api 使用较少的安全措施,因此如果您想使用这些 api 连接到您的帐户,您必须启用安全性较低的应用程序访问您的帐户。转到此链接: https://www.google.com/settings/security/lesssecureapps
