urllib2 BASIC Authentication not working

Ricardo Gladwell ricardo.gladwell at btinternet.com
Tue May 8 11:48:53 CEST 2001


Dear All,

I am attempting to use urllib2 to automate the process of logging onto a 
web site with BASIC authentication. To do this I use the following code 
fragment:

# begin python fragement

handler = HTTPBasicAuthHandler();
handler.add_password( realm, uri, user, passwd );

opener = build_opener( handler );
install_opener( opener );

f = urlopen( url );

# end python fragment

Where realm, uri, user and passwd are correct values that *should* allow 
access to url. However, when I execute the above I get a HTTP error 401 
(Authorization Required) thrown from the last line, the call to urlopen(). 
It seems that urllib2 is not calling the HTTPBasicAuthHandler for 
authentication information, and is simply throwing an error.

Please advise, TIA...

-- 
Ricardo Gladwell




More information about the Python-list mailing list