使用Python客户端库读取私有Google电子表格

使用Python客户端库读取私有Google电子表格,python,python-2.7,google-api,google-sheets,google-spreadsheet-api,Python,Python 2.7,Google Api,Google Sheets,Google Spreadsheet Api,我有一个谷歌电子表格,我想通过谷歌Python客户端读取它。这个电子表格是私人的。代码如下: import gdata import gdata.docs import gdata.spreadsheet import gdata.spreadsheet.service client = gdata.spreadsheet.service.SpreadsheetsService() client.email = 'xxx.xxx@companyName.com' clie

我有一个谷歌电子表格,我想通过谷歌Python客户端读取它。这个电子表格是私人的。代码如下:

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

为什么即使用户名/密码是正确的,并且用户名在公司域中,但在谷歌服务器上?

您面临的问题是因为谷歌安全协议。谷歌不允许任何不太安全的应用程序连接到您的帐户,这些gdata api使用的安全措施较少,因此,如果您想使用这些api连接到您的帐户,您必须启用访问您的帐户的不太安全的应用程序。转到此链接:

您可以为您的程序启用“特定于应用程序的密码”。这是一个仅从您正在使用的程序中使用的密码。谷歌的说明如下:,但要点是你应该去创建一个新密码