经过两天的阅读gspread文档、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-gspreadsheets.iam.gserviceaccount.com)共享我的电子表格--(认为是我的“真实”Gmail ID /电子邮件,但不是)
用于调试反馈... 在gspread client.py源中添加了一些print()行,以查看是否从反馈中获取到任何内容,并检查来自反馈的值。注意到我得到了一个旧值(来自上一个脚本?)
关闭并重新启动我的iPython笔记本电脑,现在它正在工作。