I need to write a python script that makes multiple HTTP requests to the same site. Unless I'm wrong (and I may very well be) urllib reauthenticates for every request. For reasons I won't go into I need to be able to authenticate once and then use that session for the rest of my requests.
I'm using python 2.3.4
Python 2
If this is cookie based authentication use HTTPCookieProcessor:
If this is HTTP authentication use basic or digest AuthHandler:
... and use same opener for every request.
Python 3
In Python3 urllib2 and cookielib were moved to http.request and http.cookiejar respectively.
If you want to keep the authentication you need to reuse the cookie. I'm not sure if urllib2 is available in python 2.3.4 but here is an example on how to do it:
Use Requests library. From http://docs.python-requests.org/en/latest/user/advanced/#session-objects :