tags:

views:

247

answers:

2

So I'm trying to download a file from a site called vsearch.cisco.com with 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 is ValueError: AbstractDigestAuthHandler doesn't know about basic

I've tried using Basic HTML Authorization handlers and even HTTPS handlers. Nothing gives me access. This error is different from all the other errors however. The other errors are simply 401 HTML errors

Any suggestions on how to do this?

A: 

As for what I tried in my tests (http://devel.almad.net/trac/django-http-digest/browser/djangohttpdigest/tests/test_simple_digest.py), error is prabably in your url - To make it working, I've included http:// part, not only host.

Almad
This isn't the case. I changed it and the same error occurs
webgoudarzi
+1  A: 

A "password manager" might help:

    mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    mgr.add_password(None, url, user, password)        
    urllib2.build_opener(urllib2.HTTPBasicAuthHandler(mgr),
                         urllib2.HTTPDigestAuthHandler(mgr))
Alex Martelli
This is good to know. Now I know that I can do that. Useful for future projects so thank you. But it still didn't fix the problem
webgoudarzi
@webgoudazi: Try to use hard-coded realm instead of None.
Almad
@almad, None there means "for every realm"
Alex Martelli