When I am trying to load something I dumped using cPickle, I get the error message:
ValueError: insecure string pickle
Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.
How could I solve this problem?
When I am trying to load something I dumped using cPickle, I get the error message:
ValueError: insecure string pickle
Both the dumping and loading work are done on the same computer, thus same OS: Ubuntu 8.04.
How could I solve this problem?
If anyone has this error using
youtube-dl
, this issue has the fix: https://github.com/rg3/youtube-dl/issues/7172#issuecomment-242961695What are you doing with data between
dump()
andload()
? It's quite common error to store pickled data in file opened in text mode (on Windows) or in database storage in the way that doesn't work properly for binary data (VARCHAR, TEXT columns in some databases, some key-value storages). Try to compare pickled data that you pass to storage and immediately retrieved from it.Check this thread. Peter Otten says:
and shows a simple way to reproduce such "corruption". Steve Holden, in the follow-up post, suggests another way to cause the problem would be to mismatch 'rb' and 'wb' (but in Python 2 and on Linux that particular mistake should pass unnoticed).
Same problem with a file that was made with python on windows, and reloaded with python on linux. Solution : dos2unix on the file before reading in linux : works as a charm !
I got the
Python ValueError: insecure string pickle
message in a different way.For me it happened after a
base64
encoding a binary file and passing throughurllib2
sockets.Initially I was wrapping up a file like this
But on the server the hash kept coming out differently for some binary files
And unpickling gave
insecure string pickle
messageBUT SUCCESS
What worked for me was to use
urlsafe_b64encode()
And decode with
References
http://docs.python.org/2/library/base64.html
https://tools.ietf.org/html/rfc3548.html#section-3
I ran into this earlier, found this thread, and assumed that I was immune to the file closing issue mentioned in a couple of these answers since I was using a
with
statement:However, since I was pushing the temp file from inside the
with
, the file still wasn't closed, so the file I was pushing was truncated. This resulted in the sameinsecure string pickle
error in the script that read the file on the remote machine.Two potential fixes to this: Keep the file open and force a flush:
Or make sure the file is closed before doing anything with it: