【问题标题】:Two calls to GetListFeed fails (gdata.spreadsheet.service.SpreadsheetsService())两次调用 GetListFeed 失败 (gdata.spreadsheet.service.SpreadsheetsService())
【发布时间】:2012-12-27 23:11:25
【问题描述】:

我正在使用 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 对象是否需要在查询之间以某种方式重置?

【问题讨论】:

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


    【解决方案1】:

    我相信你的问题是变量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'
    

    【讨论】:

    • 啊!我完全忽略了我重用了那个变量名!那是个错误。很好的收获,谢谢一百万!
    • @Allanrbo 完全没问题 - 有时这绝对是个棘手的问题 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多