Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.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中的HTTP基本身份验证处理程序错误_Python_Http_Authentication - Fatal编程技术网

Python中的HTTP基本身份验证处理程序错误

Python中的HTTP基本身份验证处理程序错误,python,http,authentication,Python,Http,Authentication,我试图从python登录到我的cPanel,但我总是收到401访问被拒绝的代码错误。我在谷歌上搜索过,尝试过,尝试过,但没有成功 下面是登录部分的代码 try: auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password("cPanel", site, base64.encodestring(user)[:-1], base64.encodestring(passwd)[:-1]) pri

我试图从python登录到我的cPanel,但我总是收到401访问被拒绝的代码错误。我在谷歌上搜索过,尝试过,尝试过,但没有成功 下面是登录部分的代码

try:
    auth_handler = urllib2.HTTPBasicAuthHandler()
    auth_handler.add_password("cPanel", site, base64.encodestring(user)[:-1], base64.encodestring(passwd)[:-1])
    print site,base64.encodestring(user)[:-1],base64.encodestring(passwd)[:-1]
    opener = urllib2.build_opener(auth_handler)
    urllib2.install_opener(opener)
    urllib2.urlopen(site)
except (urllib2.HTTPError, httplib.BadStatusLine), msg:
    print msg
谁能告诉我我到底做错了什么


我传递的URL是

为什么要对用户名和密码进行base64编码?auth handler将为您执行此操作。

我在所有示例中都看到了这一点。我尝试了纯文本,仍然是相同的401拒绝访问错误。您确定它使用的是基本身份验证吗?当我去一些我知道使用hostgator的站点并输入hostname.com:2083时,我发现它们没有使用基本身份验证。基本身份验证是浏览器显示询问用户名和密码对话框的地方。