【问题标题】:How to debug persistent 'SpreadsheetNotFound' errors using python gspread如何使用 python gspread 调试持久的“SpreadsheetNotFound”错误
【发布时间】:2016-08-10 10:33:22
【问题描述】:

在阅读 gspread 文档、gspread 博客文章和关注最多的 recent docs for using gspread 2 天后,我仍然无法打开一个 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/电子邮件,但事实并非如此)

用于调试 Feed ... 在 gspread client.py 源代码中添加了一些 print() 行,以查看我是否在提要中获得任何内容,并检查提要中的值。注意到我得到的值是旧值(来自以前的脚本?)

关闭并重新启动我的 iPython 笔记本,它现在可以工作了。

【问题讨论】:

    标签: python oauth-2.0 gspread


    【解决方案1】:

    好的,问题解决了。这是我为解决这个问题所做的:

    在 client.py 源代码中添加了一些 print() 行,以查看我是否在提要中获得任何内容,并检查提要中的值。注意到我得到的值是旧值(来自以前的脚本?)

    关闭并重新启动我的 iPython 笔记本,它现在可以工作了。

    【讨论】:

    • 您能否详细说明一下您认为您是如何做到这一点的以及您从印刷声明中学到了什么?我遇到了您上面描述的完全相同的问题。我不清楚我的 GDrive 应用是否可以访问“我的”谷歌文档。
    • 没关系!得到它的工作!使用您提到的相同文档:gspread.readthedocs.org/en/latest/…
    • 还必须与 Google Drive API 服务帐户“电子邮件地址”共享我的电子表格(例如 my.test.data@python-xyz-gspreadsheets.iam.gserviceaccount.com)
    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 2020-04-14
    • 2018-02-05
    • 2023-03-05
    • 2018-03-24
    • 2019-01-31
    • 2011-07-08
    • 2013-02-05
    相关资源
    最近更新 更多