ValueError: insecure string pickle

后端 未结 10 1539
轻奢々
轻奢々 2020-12-03 04:00

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

ValueError: insecure string pickle

Both the dumping and

10条回答
  •  生来不讨喜
    2020-12-03 04:47

    "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 "", line 1, in 
    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.

提交回复
热议问题