Python中的HTTP Basic Auth Handler错误

时间:2013-08-02 15:23:24

标签: python http authentication

我正在尝试从python登录到我的cPanel,但我总是得到401 Access Denied Code Error。我用Google搜索,尝试过并试过,但没有成功 这是登录部分的代码。

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

有人能指出我到底出错了什么吗?

我传递的网址是https://mydomain.com:2083

1 个答案:

答案 0 :(得分:0)

为什么你用base64编码用户名和密码? auth handler会为你做。

相关问题