2

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

为什么以下代码在第二个“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 对象是否需要在查询之间以某种方式重置?

4

1 回答 1

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'
于 2012-12-27T23:32:47.623 回答