urllib2: pwd protected urls

Andrei Kulakov ak at silmarill.org
Fri Apr 19 15:37:53 EDT 2002


In article <slrnac0r2p.ol1.ak at ak.silmarill.org>, Andrei Kulakov wrote:
> Hello,
> 
> I can't figure out how to get pwd-protected urls using urllib2. Here's
> what I'm doing:
> 
>>>> from urllib2 import *
>>>> a = HTTPBasicAuthHandler()
>>>> a.add_password("default", "host.net", "login", "password")
>>>> o = build_opener(a)
>>>> install_opener(o)
>>>> f = urlopen("http://host.net/file.zip")
> 
> I get Error 401: Auth required
> 
> What's 'realm'? I set it to 'default' and I also tried None.
> 

Geoff Gerrietts told me how to do this:

urlobj = urllib.urlopen("http://login:password@host.net/file.zip")


-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



More information about the Python-list mailing list