This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pickle with HIGHEST_PROTOCOL "ord() expected..."
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: drhok, tim.peters
Priority: normal Keywords:

Created on 2005-04-22 16:02 by drhok, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pickletest.py drhok, 2005-04-22 16:02 A sample script to reproduce the bug.
Messages (3)
msg25094 - (view) Author: Heiko Selber (drhok) Date: 2005-04-22 16:02
A Python script that I wrote contains a tree-like data 
structure that cannot be unpickled when pickled with 
protocol==-1 (or 2).

I attached the smallest example I could find.

If run with pickle, the result is:

Traceback (most recent call last):
  File "D:\src\misc\CDROM\python\pickletest.py", line 
68, in ?
    tree=load( f )
  File "C:\Python23\lib\pickle.py", line 1390, in load
    return Unpickler(file).load()
  File "C:\Python23\lib\pickle.py", line 872, in load
    dispatch[key](self)
  File "C:\Python23\lib\pickle.py", line 1189, in 
load_binput
    i = ord(self.read(1))
TypeError: ord() expected a character, but string of 
length 0 found

But with cPickle, the result is:

Traceback (most recent call last):
  File "D:\src\misc\CDROM\python\pickletest.py", line 
68, in ?
    tree=load( f )
EOFError

Small changes in the datastructure lead to different 
results: try changing the line
if level<4:
to
if level<1:

Now cPickle works, but not pickle.

This happens with Python 2.3.3 and 2.3.5 on Windows 
XP.
msg25095 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-04-22 17:01
Logged In: YES 
user_id=31435

How did you open the file?  You must open files holding 
pickle data in binary mode on Windows (and should open 
them in binary mode on all platforms).  IOW, you must do

f = open(whatever, 'wb')

when opening a file to which you write a pickle, and must use

f = open(whatever, 'rb')

when opening a file from which you want to read a pickle.
msg25096 - (view) Author: Heiko Selber (drhok) Date: 2005-04-22 20:54
Logged In: YES 
user_id=865975

Ouch! You're right, I failed to specify binary mode.

Sorry, closing.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41888
2005-04-22 16:02:46drhokcreate