Python urllib2基本身份验证
我正在尝试获取受密码保护的urlPython urllib2基本身份验证,python,authentication,urllib2,Python,Authentication,Urllib2,我正在尝试获取受密码保护的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.HTTPBasicAuthHand
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错误401:Unauthorized
我在跟踪
问题是什么?我已经解决:)我必须使用HTTPDigestAuthHandler而不是HTTPBasicAuthHandler