Q: Authentication with httplib
clgonsal at keeshah.penguinpowered.com
Mon Aug 23 16:08:47 EDT 1999
On Mon, 23 Aug 1999 11:27:22 +0200, Zwika Moshkowzki <zwi at turboimage.com> wrote:
> I am using httplib to access a Page on a Server:
> h = httplib.HTTP(Server)
> h.putrequest('GET', Page)
> When Server is configured not to require a passwd, I set Server="myServer",
> and everything is OK.
> My Q regards the situation where there is a need for authentication: Where
> should I put the Username+Passwd?
> Thanks in advance!
The username and password need to go in an "Authorization" header.
Something like this should work:
userid = "foo"
passwd = "bar"
# "Basic" authentication encodes userid:password in base64. Note
# that base64.encodestring adds some extra newlines/carriage-returns
# to the end of the result. string.strip is a simple way to remove
# these characters.
auth = 'Basic ' + string.strip(base64.encodestring(userid + ':' + passwd))
h = httplib.HTTP(Server)
h.putheader('Authorization', auth )
Hope that helps...
C. Laurence Gonsalves "Any sufficiently advanced
clgonsal at kami.com technology is indistinguishable
http://www.cryogen.com/clgonsal/ from magic." -- Arthur C. Clarke
More information about the Python-list