python - 使用 Python 客户端库读取私有(private) Google 电子表格

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

我有一个 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/

相关文章:

python - 嵌入式 python 中的 double

javascript - 为什么适用于 PHP 的 Google API 需要客户端 key ,而适用于 Javascript 的 Google API 则不需要?

javascript - Google API V3 一次只打开一个信息窗口

带有 *args 的 Python TypeError

python - 在没有运行 X 服务器的情况下生成 matplotlib 图

python - 如何制作一个数据透视表,其中的值按索引排列在行中

python - 使用 cv2 numpy 和 Python 2.7 调整 RGB 图像的大小

python - 如何传递列表元素作为引用?

mongodb - 将文档插入 MongoDB 集合时如何处理文档大小超过 16MB 错误

c# - 如何以编程方式为GA的网络属性创建跟踪代码