[issue5180] 3.1 cannot unpickle 2.7-created pickle

Alexander Belopolsky report at bugs.python.org
Mon Jun 28 02:43:10 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

It looks like I was able to get to the root of the problem.  I am attaching two files that demonstrate the issue:


==> pickle-bug.py <==
import pickle
import sys
class Bug:
    pass
bug = Bug()
f = open(sys.argv[1], 'w')
pickle.Pickler(f, protocol=0).dump(bug)
f.close()

==> unpickle-bug.py <==
import pickle
import sys
class Bug:
    pass
bug = pickle._Unpickler(open(sys.argv[1], 'rb')).load() # works
print(bug)
bug = pickle.Unpickler(open(sys.argv[1], 'rb')).load() # doesn't
print(bug)

$ python2 pickle-bug.py /tmp/bug.pkl
$ python3 unpickle-bug.py /tmp/bug.pkl
<__main__.Bug object at 0x1006b6f40>
Traceback (most recent call last):
  File "unpickle-bug.py", line 7, in <module>
    bug = pickle.Unpickler(open(sys.argv[1], 'rb')).load() # doesn't
_pickle.UnpicklingError: bad pickle data


The problematic pickle is really small, so I hope I'll report that I have a fix soon.

    0: (    MARK
    1: i        INST       '__main__ Bug' (MARK at 0)
   15: p    PUT        0
   18: (    MARK
   19: d        DICT       (MARK at 18)
   20: p    PUT        1
   23: b    BUILD
   24: .    STOP
highest protocol among opcodes = 0

----------
assignee: lemburg -> 
Added file: http://bugs.python.org/file17784/pickle-bug.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5180>
_______________________________________


More information about the Python-bugs-list mailing list