python - 两次调用 GetListFeed 失败 (gdata.spreadsheet.service.SpreadsheetsService())

标签 python google-docs google-sheets google-docs-api google-sheets-api

我正在使用 gdata-2.0.17.tar.gz。

为什么以下代码在第二个“for row in ssc.GetListFeed”时失败?

#!/usr/bin/python
import gdata.spreadsheet.service

key = '1AjklhasdfLJK09j2f3nFLKnff9hf28fhGFAklnf8223'

ssc = gdata.spreadsheet.service.SpreadsheetsService()
ssc.email = 'something'
ssc.password = 'something'
ssc.ProgrammaticLogin()

for row in ssc.GetListFeed(key=key).entry:
    for key in row.custom:
        print str(key) + ':' + str(row.custom[key].text)
    print

for row in ssc.GetListFeed(key=key).entry:
    for key in row.custom:
        print str(key) + ':' + str(row.custom[key].text)
    print

失败是

Traceback (most recent call last):
  File "./test.py", line 16, in <module>
    for row in ssc.GetListFeed(key=key).entry:
  File "/home/someone/something/gdata/spreadsheet/service.py", line 252, in GetListFeed
    converter=gdata.spreadsheet.SpreadsheetsListFeedFromString)
  File "/home/someone/something/gdata/service.py", line 1108, in Get
    'reason': server_response.reason, 'body': result_body}
gdata.service.RequestError: {'status': 400, 'body': 'The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn&#39;t deleted it.', 'reason': 'Bad Request'}

是否需要以某种方式在查询之间重置 SpreadsheetsService 对象?

最佳答案

我相信你的问题是变量 key - 你在这里定义它:

key = '1AjklhasdfLJK09j2f3nFLKnff9hf28fhGFAklnf8223'

但也在这里:

for key in row.custom:

由于即使在循环退出后变量仍将保留其定义,请尝试将电子表格键变量名称更改为类似 sheet_key 的名称(或更好的名称 :) )并查看它是否按预期完成。您可以在下面的代码中看到行为:

In [1]: key = 'abcdef'

In [2]: for key in ['one', 'two', 'three']:
   ...:     pass
   ...: 

In [3]: key
Out[3]: 'three'

关于python - 两次调用 GetListFeed 失败 (gdata.spreadsheet.service.SpreadsheetsService()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14062516/

相关文章:

javascript - Google Apps 脚本 - 根据单元格中的日期发送电子邮件

python - 使用boto在带有LSI的dynamoDB中创建表

python - 如何在 Ubuntu 上通过单击按钮重新启动 TeamViewer?

google-apps-script - 使用谷歌脚本创建文档时如何分割文本行(前半部分粗体,后半部分非粗体)

google-apps-script - 如何对 Google 文档/云端硬盘文档中的标题进行编号?

google-apps-script - 新的Google表格自定义功能有时会无限期显示 “Loading…”

javascript - 将二维数组复制到另一张纸

python - 在 python 的 if 语句中分配变量的 c 风格

python - 无法运行py2exe

css - 在 Ruby 中将外部 CSS 转换为内联 CSS 的工具?