Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718
  1. from urllib2 import HTTPRedirectHandler
  2. class CookieAddingHTTPRedirectHandler(HTTPRedirectHandler):
  3. """The standard python HttpRedirectHandler doesn't add a cookie to the new request after a 302. This handler does."""
  4. def __init__(self, cookie_jar):
  5. self.cookie_jar = cookie_jar
  6. # This really ought to call the superclasses init method, but there doesn't seem to be one.
  7. def redirect_request(self, *args):
  8. new_request = HTTPRedirectHandler.redirect_request(self, *args)
  9. # We need to add a cookie from the cookie_jar
  10. self.cookie_jar.add_cookie_header(new_request)
  11. return new_request