我很困惑,为什么我无法使用urllib2从FriendFeed下载一些JSON响应的全部内容。urllib2不检索整个HTTP响应
>>> import urllib2
>>> stream = urllib2.urlopen('http://friendfeed.com/api/room/the-life-scientists/profile?format=json')
>>> stream.headers['content-length']
'168928'
>>> data = stream.read()
>>> len(data)
61058
>>> # We can see here that I did not retrieve the full JSON
... # given that the stream doesn't end with a closing }
...
>>> data[-40:]
'ce2-003048343a40","name":"Vincent Racani'
如何使用urllib2检索完整响应?
网站的榜样的网站破碎。尝试在浏览器中。 – 2009-12-01 05:47:18
当使用Ubuntu 9.04上的Firefox 3.0点击该URL时,我得到了全部165K的响应。检索到的JSON文档在我的浏览器中很好地形成。 – gotgenes 2009-12-01 14:23:41
是的,该网站已损坏。但这肯定是'urllib'和'urllib2'中的一个错误,因为其他工具(curl,wget)报告的响应不完整。很高兴知道python库中有什么问题。 – 2009-12-01 14:46:03