您是否尝试过在自己的HTTP处理程序中设置调试级别?将您的代码更改为如下所示:
>>> import urllib2>>> handler=urllib2.HTTPHandler(debuglevel=1)>>> opener = urllib2.build_opener(handler)>>> urllib2.install_opener(opener)>>> resp=urllib2.urlopen('http://www.google.com').read()send: 'GET / HTTP/1.1 Accept-Encoding: identity Host: www.google.com Connection: close User-Agent: Python-urllib/2.7'reply: 'HTTP/1.1 200 OK'header: Date: Sat, 08 Oct 2011 17:25:52 GMTheader: Expires: -1header: Cache-Control: private, max-age=0header: Content-Type: text/html; charset=ISO-8859-1... the remainder of the send / reply other than the data itself因此,要添加的三行是:
handler=urllib2.HTTPHandler(debuglevel=1)opener = urllib2.build_opener(handler)urllib2.install_opener(opener)... the rest of your urllib2 pre...
这将显示stderr上的原始HTTP发送/回复周期。
从评论编辑
这样行吗?
... same pre as above this lineopener=urllib2.build_opener(authhandler, urllib2.HTTPHandler(debuglevel=1))... rest of your pre



