2009-06-18 58 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))