This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jondebonis
Recipients jondebonis
Date 2009-07-28.02:07:09
SpamBayes Score 0.0030987915
Marked as misclassified No
Message-id <1248746834.41.0.511434731236.issue6588@psf.upfronthosting.co.za>
In-reply-to
Content
Added ability to insert cookies into cookie jar.

Fixed problem where some domain names are prepended with '.' and others 
were not.

Fixed problem with _LWPCookieJar.py to handle case where version = None

----
import urllib2, urllib, time
import cookielib
            
req_url = 'http://google.com'

## OPEN COOKIE JAR - Optional
cj = cookielib.CookieJar()

cookie_handler = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_handler)
urllib2.install_opener(opener)

req = urllib2.Request(url=req_url)
    
cj.add_cookie(req, 'cname2', 'cval2',
                {'expires':  int(time.time()) + 3600,})

cj.add_cookie(req, 'cname3', 'cval3') 

print "-" * 45
print "Cookies before first request is sent:"
for index, cookie in enumerate(cj):
    print index, '  :  ', cookie

res = urllib2.urlopen(req)
# Google will redirect, and clear the additional cookies
print "-" * 45
print "Cookies after first request is sent:"
print "(google cleared extra cookies)"
for index, cookie in enumerate(cj):
    print index, '  :  ', cookie
---
History
Date User Action Args
2009-07-28 02:07:14jondebonissetrecipients: + jondebonis
2009-07-28 02:07:14jondebonissetmessageid: <1248746834.41.0.511434731236.issue6588@psf.upfronthosting.co.za>
2009-07-28 02:07:11jondebonislinkissue6588 messages
2009-07-28 02:07:11jondeboniscreate