我正在使用gdata-2.0.17.tar.gz。
为什么以下代码在第二个“for 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't deleted it.', 'reason': 'Bad Request'}
是否需要以某种方式在查询之间重置SpreadsheetsService对象?
答案 0 :(得分: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'