On Tue, Mar 08, 2005 at 11:50:12AM -0500, Kent Johnson wrote:
> 
> Paul Tremblay wrote:
> 
> You can use urllib2 to do this. It is a little work to set it up to use 
> Basic authentication. Here is an example (slightly modified from the 
> urllib2 example page):
> 
> import urllib2
> 
> # Create an OpenerDirector with support for Basic HTTP Authentication...
> auth_handler = urllib2.HTTPBasicAuthHandler()
> auth_handler.add_password('realm', '127.0.0.1', 'username', 'password')
> opener = urllib2.build_opener(auth_handler)
> # ...and install it globally so it can be used with urlopen.
> urllib2.install_opener(opener)
> print urllib2.urlopen('http://127.0.0.1/my/protected/page.html').read()
> 
> Kent
> 

This is giving me 401 error, authorization required. Here's what I have:


auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
print urllib2.urlopen('http://nnn.nnn.n.n').read()

This is almost the literal code, except I changed my log in name and
passowrd.

What am I supposed to put for realm? I checked the docs on line, and it
doens't mention what realm is.

Also, I assume I am supposed to use the loopback address when I set up
the handler?

Also, I know I am going to have another question once I solve this one,
and since it is directly related, I'll ask it now. How can I use a
password system that is not hardcoded in my text? Should I just setup a
password file? 

Thanks

Paul



-- 

************************
*Paul Tremblay         *
[EMAIL PROTECTED]    *
************************
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to