使用urllib2的Python身份验证

2024-05-18 18:22:25 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想用python从一个名为vsearch.cisco.com的网站下载一个文件

[Python]

#Connects to the Cisco Server and Downloads files at the URL specified

import urllib2

#Define Useful Variables

url = 'http://vsearch.cisco.com'
username = 'xxxxxxxx'
password = 'xxxxxxxx'
realm = 'CEC'

# Begin Making connection

# Create a Handler -- Also could be where the error lies

handler = urllib2.HTTPDigestAuthHandler()
handler.add_password(realm,url,username,password)

# Create an Opener

opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

try:
    urllib2.urlopen(url)
    print f.read()

except urllib2.HTTPError, e:
    print e.code
    print e.header

[/python]

我的错误是ValueError:AbstractDigestAuthHandler不知道

我试过使用基本的HTML授权处理程序,甚至HTTPS处理程序。没有什么能让我进入。但是,此错误与所有其他错误不同。其他的错误是401个HTML错误

有什么建议吗?


Tags: thecomurl错误createusernamepasswordopener

热门问题