All pastes #896523 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-08 19:06 UTC
rendered paste body
# OLD WAY
# f = urllib2.urlopen(url, urllib.urlencode(params))

# New way with cookies!

COOKIEFILE = 'cookies.lwp'   # Change this to your cookie jar filename

cj = cookielib.LWPCookieJar()

# If there's a cookie jar file, open it
if os.path.isfile(COOKIEFILE):
    cj.load(COOKIEFILE)

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
f = urllib2.urlopen(urllib2.Request(url, urllib.urlencode(params)))

# Now get the answer or whatever you want to do next..
response = urllib2.urlopen(f)

# Don't forget to save the cookies to a file when you're done!