Using Cookie and Proxy handler with urllib2

Joshua Gilman joshuagilman at
Sun Feb 10 05:15:33 CET 2008

Hello, here is my current code:

import urllib, urllib2, cookielib

class wrapper:
    def __init__(self):

    def request(self, address, postData=None, headers={ }):
        if not postData == None:
            postData = urllib.urlencode(postData)
        req = urllib2.Request(address, postData, headers)
        return urllib2.urlopen(req).read()

    def loadCookies(self, cookieFile):

    def saveCookies(self, cookieFile):

    def useProxy(self, proxy):
        proxymap = {'http': proxy}
        self.cookieJar = cookielib.LWPCookieJar()

        director = urllib2.OpenerDirector()


    def setupCookies(self):
        self.cookieJar = cookielib.LWPCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(

proxyhttp = wrapper()
postData = {'username': username, 'password': password}
content = proxyhttp.request('', postData)

Now, basically what this should do is send a POST request to login.php using
the given proxy and then save the returned cookies using the cookie handler.
Either I'm doing something wrong or the proxy and cookie handler don't place
nicely together. Here is the resulting error:

  File "C:\Python25\neolib\", line 11, in request
    return urllib2.urlopen(req).read()
  File "C:\Python25\lib\", line 121, in urlopen
    return, data)
  File "C:\Python25\lib\", line 380, in open
    response = meth(req, response)
  File "C:\Python25\lib\", line 1124, in http_response
    self.cookiejar.extract_cookies(response, request)
  File "C:\Python25\lib\", line 1627, in extract_cookies
    _debug("extract_cookies: %s",
AttributeError: 'NoneType' object has no attribute 'info'

I don't know much about these handlers to really understand what's going
wrong. I assume it has to be something with these two handlers conflicting
because I can't seem to find anything wrong with my code. Is this a bug or
am I doing something wrong? Help is much appreciated, thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list