我有一个 Google 电子表格,我想通过 Google Python 客户端来读取它。该电子表格是私有(private)的。这是代码:
import gdata
import gdata.docs
import gdata.spreadsheet
import gdata.spreadsheet.service
client = gdata.spreadsheet.service.SpreadsheetsService()
client.email = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8a0a0a0f6a0a0a098bbb7b5a8b9b6a196b9b5bdf6bbb7b5" rel="noreferrer noopener nofollow">[email protected]</a>'
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
关于python - 使用 Python 客户端库读取私有(private) Google 电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26614321/