添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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:

pickle.dump([c for c in cj], dumpFile)

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.

>>> import cookielib
>>> import dill
>>> cj = cookielib.CookieJar()
>>> _cj = dill.dumps(cj)
>>> cj_ = dill.loads(_cj)
<CookieJar[]>
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.1.24.35891