可以将cookiejar对象腌制吗? [英] Can a cookiejar object be pickled?

查看:95
本文介绍了可以将cookiejar对象腌制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图像这样腌制CookieJar对象:

I tried pickling a CookieJar object like this:

import cookielib
import pickle

dumpFile = open('cookie.dump','w')
cj = cookielib.CookieJar()
pickle.dump(cj, dumpFile)

它引发了以下异常:

raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle lock objects

可以给CookieJar腌吗?

Can a CookieJar be pickled?

推荐答案

所问问题的答案为否":罐子本身不能腌制.

The answer to the question as asked is "no": the jar itself is not pickle-able.

但是,包含在罐子中的饼干:

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

例如,

可以解决问题. (然后,您可以加载结果并将cookie列表插入新的jar中.您可能要先检查它们是否已过期,但是首先要检查它们的到期时间.根据您进行酸洗的时间,甚至可能希望在转储之前进行检查. )

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.)

这篇关于可以将cookiejar对象腌制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆