北极星光 发表于 2017-5-1 15:04:18

python中urllib和urllib2不同的调试方法

使用urllib发http请求时:

import urllib, httplib
httplib.HTTPConnection.debuglevel = 1
urllib.urlopen(”http://google.com”)

使用urllib2发http请求时:

import urllib2
handler=urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
request = urllib2.Request(url,headers,data)


debuglevel设置微1可以查看header、body等内容
页: [1]
查看完整版本: python中urllib和urllib2不同的调试方法