Mailing List Archive

Authentication with httplib
> 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
Authentication with httplib [ In reply to ]
In article <7prana$a0p$1@minus.oleane.net>,
Mathieu Lecarme <zehp@francemel.com> wrote:
>
>you should rather use urllib :

No, you shouldn't, unless you're running an interactive process. urllib
expects stdin to provide name and password. We got bitten by this one;
because we don't care about authorization (yet) but do care about
redirection, we had to subclass fancy_url_opener() (or whatever the
exact spelling is).

If someone is running a batch process, zie will either need to do what
the original poster was doing (use httplib directly) or subclass
urlopen() to make it work in a batch environment.

I've actually got some other problems with urlopen() in that it doesn't
return the HTTP return code.
--
--- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)