python - Python 的 gspread 中特定 Google 表格电子表格的持续性 SpreadsheetNotFound 错误

标签 python google-api google-sheets gspread

我正在使用 gspread从数百个 Google 表格电子表格中收集数据。我解析 Google 云端硬盘存储在本地目录中的文件,并获取指定文件夹中所有电子表格的 URL。然后,我使用 python 包装器遍历 URL,并使用 shell 脚本包装器在连接出现故障时跳转启动 python 包装器。

出现故障的原因之一是 SpreadsheetNotFound 错误。我做了大约一半的快速检查,发现我的电子表格中有 21/139 (~15%) 总是出现此错误(如果找不到五次,我会跳过电子表格)。我已经使用 iPython 并使用 open_by_url、open_by_key 和 open(带有标题)手动测试了这些,但它们都返回相同的 SpreadsheetNotFound 错误。最令人沮丧的部分是能够直接从我的错误消息中复制 URL,将其粘贴到浏览器中,并且浏览器可以毫无问题地直接进入电子表格。第二个最令人沮丧的部分是,它适用于约 85% 的电子表格,但 85% 的电子表格并不能完全削减它。

我什至不确定这是否可以解决。我很好奇是否还有其他人遇到过 gspread 的这个问题。

感谢任何反馈。

编辑 1:嗯,失败的电子表格都是在 2/2/15 之前创建的。较旧的工作表已更新为最新版本的云端硬盘 - 这可能会对 API 产生影响。

最佳答案

来自 Gspread 文档:

ClientLogin is deprecated:
https://developers.google.com/identity/protocols/AuthForInstalledApps?csw=1
Authorization with email and password will stop working on April 20, 2015.
Please use oAuth2 authorization instead:
http://gspread.readthedocs.org/en/latest/oauth2.html

所以我假设您使用的是 oAuth2。这意味着您需要将该 json 证书文件中的电子邮件地址添加到电子表格中。

Using OAuth2 for Authorization

参见第 7 点:

Go to Google Sheets and share your spreadsheet with an email you have in your json_key['client_email']. Otherwise you’ll get a SpreadsheetNotFound exception when trying to open it.

关于python - Python 的 gspread 中特定 Google 表格电子表格的持续性 SpreadsheetNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31150633/

相关文章:

python - 使用 sqlalchemy.engine.url.URL 为 mssql+pyodbc 构建连接 URL

Python 2.4 内联 if 语句

python:如果键不在字典中,则添加键。防止多线程竞争条件

python - 如何知道reportlab PDF 页面是否已满?

google-apps-script - 谷歌应用脚​​本: "Error 401: deleted_client The OAuth client was deleted" All of a sudden?

google-api - 如何获得访问 Google Play 开发者 API 的授权

javascript - 加载 GeoJson Google API - CORS 政策

没有任何应用程序 ID 的 API 配额

dynamic - 动态排除行

web-applications - 谷歌电子表格更新多个文件中的同一行