Python Authentication with urllib2

So I'm trying to download a file from vsearch.cisco.com using python

[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]

My error ValueError: AbstractDigestAuthHandler does not know about the main

I tried using basic HTML authorization handlers and even HTTPS handlers. Nothing gives me access. However, this error is different from all other errors. Other errors are just 401 HTML errors

Any suggestions on how to do this?

+4
source share
2 answers

Password Manager can help:

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

As for what I tried in my tests ( http://devel.almad.net/trac/django-http-digest/browser/djangohttpdigest/tests/test_simple_digest.py ), the error in your URL is very convenient - so that to make it work, I 'turned on http: // part, not just the host.

0
source

Source: https://habr.com/ru/post/1286432/


All Articles