ValueError: insecure pickle string

Peter Otten __peter__ at web.de
Mon Mar 28 12:30:49 EDT 2011


pradeepbpin wrote:

> I am encountering 'Value Error: insecure string pickle' when trying to
> execute the script on Ubuntu. The same script and the pickled file
> works without any problem in Windows. For working in Ubuntu I just
> copied both the script file and pickled file from Windows.
> 
> 
> How can I get out of this error? Rather, I would like to have common
> script and pickled file that can work platform independently.

Try opening the file in universal newline mode:

f = open("my.pickle", "U")
print pickle.load(f)

This will convert Windows "\r\n" line endings to "\n".

For new data: an alternative is to open the file in binary mode for both 
reading and writing on all platforms. This will also allow you to switch to 
the more efficient binary pickle protocols.



More information about the Python-list mailing list