Authentication with httplib

Mathieu Lecarme zehp at francemel.com
Mon Aug 23 07:20:48 EDT 1999


> I am using httplib to access a Page on a Server:
>
>     .....
>      h = httplib.HTTP(Server)
>      h.putrequest('GET', Page)
>      h.endheaders()
>     .....
>
> When Server is configured not to require a passwd, I set
Server="myServer",
> Page="/myPage",
> and everything is OK.
>
> My Q regards the situation where there is a need for authentication: Where
> should I put the Username+Passwd?

you should rather use urllib :
    import urllib
    file = urllib.urlopen('http://login:password@www.foo.com/truc.html')

or if you wont to know how it's work, have a look of urllib line 248 and
after

Mathieu






More information about the Python-list mailing list