在阅读了两天的gspread文档、gspread博客文章之后,我仍然无法打开一个Google电子表格。我建立了一个GDrive API服务帐户。看来我的OAuth2凭据正在工作,但我仍然经常遇到“SpreadsheetNotFound”错误。
我的代码看起来是这样的,在尝试打开Google电子表格之前不会出现任何错误消息:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']

jsonfile    = '/path/Python-data-GSpreadsheets-dbbc-99.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(jsonfile,scope)

# get authorized to access data
gc = gspread.authorize(credentials)
# gc returns with no error messages, so far OK
wks = gc.open('SSTEst123').sheet1  #fails here
#throws SpreadsheetNotFound error

是的,我已经添加了我的gmail电子邮件地址作为授权编辑(尝试与否),因为服务帐户应该可以访问我的所有数据无论如何,我正在与我自己重新共享我的电子表格。
我还能试着找出它失败的原因吗?
关于如何调试它为什么不能打开任何电子表格有什么想法吗?
好吧,我是这样解决的。
必须与Google Drive API服务帐户“电子邮件地址”(例如my.test.data@python-xyz-g spreadsheets.iam.g service account.com)共享我的电子表格(以为这是我的“真实”gmail ID/电子邮件,但事实并非如此)
用于调试源。。。
在gspread client.py源代码中添加了一些print()行,以查看是否在提要中获得了任何信息,并检查提要中的值。注意到我得到了一个旧值(来自前一个脚本?)
关闭并重新启动我的iPython笔记本,它现在正在工作。

最佳答案

好的,问题解决了。我是这么想的:
在client.py源代码中添加了一些print()行,以查看是否在提要中获得了任何信息,并检查提要中的值。注意到我得到了一个旧值(来自前一个脚本?)
关闭并重新启动我的iPython笔记本,它现在正在工作。

10-06 01:52