Strange KeyError using cPickle

Tim Peters tim.peters at gmail.com
Wed Jun 1 22:19:17 EDT 2005


[Tim Peters]
>> What is "XWwz"?  Assuming it's a bizarre typo for "open", change the
>> 'w' there to 'wb'.  Pickles are binary data, and files holding pickles
>> must be opened in binary mode, especially since:
>>

>>> ...
>>> (on WinXP, CPython 2.4.1)

[Rune Strand]
> Thanks Tim. The bizarre 'typo' appears to be caused by ad-blocking
> software confusing python code with javascript (i think).
>
> I had the feeling this was a red facer.
>
> Setting the protocol to 0 (text) also  make it work.

Not really.  Repeat:  pickles are binary data, and files holding
pickles must be opened in binary mode.  The horribly named "text mode"
pickles (and this is one reason they're called "protocol 0" now
instead) are binary data too.  Pickles created with protocol 0 may
also fail if transported across platforms, if written to a file opened
in text mode.  Pickle files should always be opened in binary mode,
regardless of pickle protocol, and regardless of platform.



More information about the Python-list mailing list