Storing cookielib cookies in a database

Posted by Mridang Agarwalla on Stack Overflow See other posts from Stack Overflow or by Mridang Agarwalla
Published on 2010-06-12T14:04:06Z Indexed on 2010/06/12 14:13 UTC
Read the original article Hit count: 265

Filed under:
|
|

Hi,

I'm using the cookielib module to handle HTTP cookies when using the urllib2 module in Python 2.6 in a way similar to this snippet:

import cookielib, urllib2
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://example.com/")

I'd like to store the cookies in a database. I don't know whats better - serialize the CookieJar object and store it or extract the cookies from the CookieJar and store that. I don't know which one's better or how to implement either of them. I should be also be able to recreate the CookieJar object.

Could someone help me out with the above?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about urllib2