python urllib2 urlopen 响应:
<addinfourl at 1081306700 whose fp = <socket._fileobject object at 0x4073192c>>
预期的:
{“令牌”:“mYWmzpunvasAT795niiR”}
您需要将生成的类文件对象绑定到一个变量,否则解释器只是通过以下方式转储它repr
:
>>> import urllib2
>>> urllib2.urlopen('http://www.google.com')
<addinfourl at 18362520 whose fp = <socket._fileobject object at 0x106b250>>
>>>
>>> f = urllib2.urlopen('http://www.google.com')
>>> f
<addinfourl at 18635448 whose fp = <socket._fileobject object at 0x106b950>>
要获取实际数据,您需要执行read()
.
>>> data = f.read()
>>> data[:50]
'<!doctype html><html itemscope="itemscope" itemtyp'
要查看返回的标题:
>>> print f.headers
Date: Thu, 23 Aug 2012 00:46:22 GMT
Expires: -1
Cache-Control: private, max-age=0
... etc ...
在您致电后添加以下内容urlopen
print feed.read()
也许您会发现使用该requests
库比使用urllib2
.