cPickle from 2.2 to 2.1

Tim Peters tim.one at comcast.net
Sun Dec 14 12:45:13 EST 2003


[paul]
> I use cPickle in a small .cgi to save data. It run's fine on python
> 2.2.3 (used for development) but fails on 2.1.1 (webserver) with:
>
>    File "spyblog.py", line 543, in __init__
>      self.entry = cPickle.load(open(log + self.filename, 'r+'))
> SystemError: Failed to import class _reconstructor from module
> copy_reg
>
>
> If I create the file on the webserver everything works, so apparently
> the 2.1.1 version of cPickle can't read files generated with the newer
> one. Does it mean the cPickle format is not compatible across
> versions?

Sorry, not enough information to say for sure.  The specific error you're
seeing *can* occur when trying to unpickle a pickle of a new-style class
instance under a version of Python before new-style classes were introduced.
Since new-style classes were introduced in 2.2, a pickle made under 2.2,
containing a new-style class instance, can raise the exception you're seeing
if you try to unpickle it under any version of Python before 2.2.  It's not
that the pickle format is incompatible then, it's that you're asking an
older Python to unpickle an object of a type the older Python doesn't know
anything about.

IOW, if you want to read current pickles under older Pythons, you have to
avoid pickling anything of a type that didn't exist in the older Pythons.
For another example, you can't expect a pickle of a Unicode string to get
unpickled under Python 1.5.2 either (since Unicode strings didn't exist in
1.5.2).






More information about the Python-list mailing list