2009-06-18 56 views
4

所以我想从一个网站名为vsearch.cisco.com下载文件与PythonPython的认证与urllib2的

[巨蟒]

#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 

[/蟒蛇]

我错误是ValueError:AbstractDigestAuthHandler不知道基本

我试过使用基本的HTML授权处理程序,甚至HTTPS处理程序。没有任何东西给我访问然而,这个错误与所有其他错误不同。其他错误只是401 HTML错误

有关如何做到这一点的任何建议?

+0

我一直在试图检查什么授权协议http://vsearch.cisco.com即将到来,但该网站似乎是目前下跌 - - 当它重新开始时,或许让我们知道w /评论,这样我就可以试着看看我能否发现问题! – 2009-06-19 00:15:45

+0

它没有下降......它只是密码保护......它不应该是下降 – webgoudarzi 2009-07-08 00:19:53

回答

8

A“密码管理器”可以帮助:

mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() 
    mgr.add_password(None, url, user, password)   
    urllib2.build_opener(urllib2.HTTPBasicAuthHandler(mgr), 
         urllib2.HTTPDigestAuthHandler(mgr))