urllib2 auth error

rtilley rtilley at vt.edu
Mon Feb 20 18:32:46 EST 2006


I get this error:

HTTP Error 401: Authorization Required

When I do this:

try:
     handler = urllib2.HTTPBasicAuthHandler()
     handler.add_password('realm', 'website', 'user', 'pass')
     opener = urllib2.build_opener(handler)
     urllib2.install_opener(opener)
     f = urllib2.urlopen('http://website')
     print f.read()
     f.close()
except Exception, e:
     print e

I have the right username and password. I may be using the above code 
wrong. Any tips?

Thanks,
Brad



More information about the Python-list mailing list