栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何调试使用基本身份验证处理程序的urllib2请求

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何调试使用基本身份验证处理程序的urllib2请求

您是否尝试过在自己的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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/653389.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号