我正在尝试获取受密码保护的url
theurl = 'http://92.xx.xxx.x:80xx/connectioncounts'
username = ''
password = ''
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, theurl, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
opener.open(theurl)
但是总是得到urllib2.HTTPError:HTTP Error 401:Unauthorized
我在跟踪https://docs.python.org/2.7/howto/urllib2.html#id6
有什么问题吗?在
我解决了:)我一定是用了HTTPDigestAuthHandler而不是HTTPBasicAuthHandler。在
相关问题 更多 >
编程相关推荐