Alexander Belopolsky <[email protected]> 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 <[email protected]>
<http://bugs.python.org/issue5180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com