urllib, python 1.52, basic authentication

Steve Purcell stephen_purcell at yahoo.com
Thu Apr 19 02:29:38 EDT 2001


Ari Davidow wrote:
> I am trying to request a page that is being protected by basic authentication.
> 
> import httplib, urllib,binascii
> cookie = binascii.b2a_base64("user:password")
> h = httplib.HTTP("www.site.com")
> h.putrequest("GET", "/admin/flushgo.html?ok=ok" "HTTP/1.0\r\n")


I think you can (and should) omit that HTTP/1.0 specifier and the line ending.

       h.putrequest("GET", "/admin/flushgo.html?ok=ok")


> h.putheader("Proxy-authorization", "Basic %s" % cookie)


And here, according to the source of urllib2.py, this should be changed to:

       h.putheader("Authorization", "Basic %s" % cookie)

Good luck,

-Steve


-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list