I tried pickling a CookieJar object like this:
import cookielib
import pickle
dumpFile = open('cookie.dump','w')
cj = cookielib.CookieJar()
pickle.dump(cj, dumpFile)
It raised the following exception:
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle lock objects
Can a CookieJar be pickled?
The answer to the question as asked is "no": the jar itself is not pickle-able.
However, the cookies contained in the jar, are:
will do the trick, for instance. (You can then load the result and insert the list of cookies into a new jar. You will probably want to check them for expiration and such first though. Depending on when you're doing the pickling you might even want to check before dumping.)
The answer is "yes", but only if you use a better serializer than
pickle
.