ValueError: insecure pickle string

P

pradeepbpin

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

Peter Otten

pradeepbpin said:
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.
 
S

Steven D'Aprano

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.

What version of Python are you using on Ubuntu? Is it the same version of
Python on Windows?

Please show the full error traceback and the string that causes the error.
 
P

pradeepbpin

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.

Writing and reading the pickled file in binary mode seems to be
working. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top