ClientCookie bug (followup)

Mark Carter cartermark46 at ukmail.com
Mon Aug 25 11:08:15 EDT 2003


jjl at pobox.com (John J. Lee) wrote in message news:<87isos0zng.fsf at pobox.com>...
> cartermark46 at ukmail.com (Mark Carter) writes:
> 
> > > No really, I wasn't joking: you *never* need to use add_cookie_header
> > > / extract_cookies if you're using urllib2 (at least, I can't think of
> > > any possible reason to do so).  It can only break things.
> > 
> > I must admit that I don't really know what I am doing. How would you
> > simplify the following code:
> [...]
> 
> It doesn't tend to encourage people to help you if you don't even
> *try* to apply their advice, and just expect them to do all your work
> for you.  Read that paragraph you quoted (and the rest I posted in
> that message and previously), try doing what it suggests, then come
> back here if you need to.

I've looked again, and add_cookie_header() definitely(!) is required
for the following code to work:

def go10():
    #works with win xp
    import ClientCookie
    c = ClientCookie.MSIECookieJar(delayload=1)
    c.load_from_registry(username='mcarter') #only need username for
win9x

    import urllib2
    url = 'http://businessplus.hemscott.net/corp/crp03733.htm'
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    request2 = urllib2.Request(url)
    c.add_cookie_header(request2)
    response2 = urllib2.urlopen(request2)

    print response2.geturl()
    print response2.info()  # headers
    for line in response2.readlines():  # body
         print line

If I take out add_cookie_header(), then the wrong page (i.e. the
registration page) is returned.

I will investigate further and let you know what I find.




More information about the Python-list mailing list