【问题标题】:Reading a private Google spreadsheet using a Python client library使用 Python 客户端库读取私有 Google 电子表格
【发布时间】:2014-10-28 17:07:50
【问题描述】:

我有一个 Google 电子表格,我想通过 Google 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

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

【问题讨论】:

    标签: python python-2.7 google-api google-sheets google-spreadsheet-api


    【解决方案1】:

    您面临的问题是由于 google 安全协议。 Google 不允许任何不太安全的应用程序连接到您的帐户,并且这些 gdata api 使用较少的安全措施,因此如果您想使用这些 api 连接到您的帐户,您必须启用访问您的帐户以访问不太安全的应用程序。转到此链接: https://www.google.com/settings/security/lesssecureapps

    【讨论】:

      【解决方案2】:

      您可以为您的程序启用“应用专用密码”。这是一个仅用于您正在处理的程序的密码。 Google 的说明在这里:https://support.google.com/accounts/answer/185833?rd=1,但要点是您应该转到https://security.google.com/settings/security/apppasswords 并创建一个新密码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-04
        • 1970-01-01
        • 2011-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-04
        相关资源
        最近更新 更多