Search code examples
urllib2basic-authentication

urllib2 basic authentication is a hit and miss


i am having some problem with the authentication in urllib2, it is hitting some pages

like i have

https://localhost:5260/user

I am using a basic authentication for this and its working fine, a page is retrieved correctly

username = 'test'
password = 'test'
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
authheader =  "Basic %s" % base64string

but when i apply the same thing to another page which the user is an admin and trying to access, its not returning the page with authentication

https://localhost:5260/post/250

I understand this is something do with the state which is saved, but i am not able to figure it out.


Solution

  • This seems trivial now, I need to set the cookie and pass that information to the server :)

    The link below gives a good description of how to look at it.

    http://www.voidspace.org.uk/python/articles/cookielib.shtml