tags:

views:

201

answers:

4

Python problem: When I am trying to load sth 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?

A: 

Paste up demo code showing where the error occurs and how you're trying to implement it and I'll be happy to help.

NB does this site email me notifications of updates?

Richo
Thanks. The code is in a django project. I'll need to send you a lot of classes. It may take me a lot of time to prepare them.So first let me explain more:the data is dumped and loaded using the same computer and same python. If I can dump the data, why can't I load it? It is said that cPickle is picky. I will try pickle instead. Wait for me.
Peter Long
Sure. When you've got a reproducible error, let me know :D
Richo
A: 

Check this thread. Peter Otten says:

A corrupted pickle. The error is raised if a string in the dump does not both start and end with " or '.

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

Alex Martelli
I have read that article. I can't agree with him. As my program is running on linux and python 2. And there should be any miss-match ' or ". As the dump is generated by python too, I think the dump method of python can handled the miss-match issue, right?
Peter Long
Alex Martelli
+1  A: 

What are you doing with data between dump() and load()? 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.

Denis Otkidach
A: 

Hi All,

Thank you for the answers. But the problem hasn't been resolved, I made a workaround for my program.

Here is the scenario: I read large amount of data from internet, generate thousands of objects and dump them to hard disk. Later I load these objects and store them into to database. Some times, some of the load operation will fail. While most of the time, the load operation works well. So it is quite weird.

For now I just ignore the problem. And by the way, I just switched a broken memory for my server. Don't know if the problem is caused by a broken memory. So let's forget about this problem.

Thank you all again!

Peter Long