ValueError:不安全的字符串泡菜 [英] ValueError: insecure string pickle

查看:82
本文介绍了ValueError:不安全的字符串泡菜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试加载使用cPickle转储的内容时,收到错误消息:

When I am trying to load something I dumped using cPickle, I get the error message:

ValueError: insecure string pickle

转储和加载工作都在同一台计算机上完成,因此在同一操作系统上:Ubuntu 8.04.

Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.

我该如何解决这个问题?

How could I solve this problem?

推荐答案

比Python中从未发现的bug更有可能在一种每天在世界范围内使用数十亿次的功能中":它总是令人惊讶我是如何在这些论坛中跨人交流的.

"are much more likely than a never-observed bug in Python itself in a functionality that's used billions of times a day all over the world": it always amazes me how cross people get in these forums.

解决此问题的一种简单方法是忘记关闭用于转储数据结构的流.我只是做

One easy way to get this problem is by forgetting to close the stream that you're using for dumping the data structure. I just did

>>> out = open('xxx.dmp', 'w')
>>> cPickle.dump(d, out)
>>> k = cPickle.load(open('xxx.dmp', 'r'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: insecure string pickle

这就是为什么我首先来到这里的原因,因为我看不到自己做错了什么.
然后,我实际上考虑了这个问题,而不是仅仅来这里,而是意识到我应该这样做:

Which is why I came here in the first place, because I couldn't see what I'd done wrong.
And then I actually thought about it, rather than just coming here, and realized that I should have done:

>>> out = open('xxx.dmp', 'w')
>>> cPickle.dump(d, out)
>>> out.close() # close it to make sure it's all been written
>>> k = cPickle.load(open('xxx.dmp', 'r'))

容易忘记.不需要人们被告知他们是白痴.

Easy to forget. Didn't need people being told that they are idiots.

这篇关于ValueError:不安全的字符串泡菜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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