Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python urllib2基本身份验证_Python_Authentication_Urllib2 - Fatal编程技术网

Python urllib2基本身份验证

Python 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

我正在尝试获取受密码保护的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错误401:Unauthorized

我在跟踪

问题是什么?

我已经解决:)我必须使用HTTPDigestAuthHandler而不是HTTPBasicAuthHandler