urllib, urllib2 HTTPDigestAuthHandler() bug?
Stephen Steiner
ssteiner at mac.com
Thu Feb 6 16:06:30 EST 2003
Has anyone tried opening a URL that requires authorization?
Here's my test program (I've removed the real password etc.) but this
is pretty much straight out of the top of the urllib2.py file:
import urllib2
# set up authentication info
authinfo = urllib2.HTTPDigestAuthHandler()
authinfo.add_password('realm', 'host', 'username', 'password')
proxy_support = urllib2.ProxyHandler({"http" : "http://ahad-haam:3128"})
# build a new opener that adds authentication and caching FTP handlers
opener = urllib2.build_opener(proxy_support, authinfo,
urllib2.CacheFTPHandler)
# install it
urllib2.install_opener(opener)
f = urllib2.urlopen('http://theaddressoftheDAVserver')
buf = f.read()
f.close()
print "read %d bytes" % len(buf)
print buf
And, here's what I get when I run it...
Traceback (most recent call last):
File "urltest.py", line 19, in ?
f = urllib2.urlopen('http://idclinux2/dav')
File "/usr/local/lib/python2.2/urllib2.py", line 138, in urlopen
return _opener.open(url, data)
File "/usr/local/lib/python2.2/urllib2.py", line 322, in open
'_open', req)
File "/usr/local/lib/python2.2/urllib2.py", line 301, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.2/urllib2.py", line 794, in http_open
return self.do_open(httplib.HTTP, req)
File "/usr/local/lib/python2.2/urllib2.py", line 788, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "/usr/local/lib/python2.2/urllib2.py", line 348, in error
return self._call_chain(*args)
File "/usr/local/lib/python2.2/urllib2.py", line 301, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.2/urllib2.py", line 400, in
http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Authorization Required
Exit 1
Clues, anyone? Has anyone used this?
Thanks in advance for any help.
Steve
More information about the Python-list
mailing list