Strange KeyError using cPickle
tim.peters at gmail.com
Thu Jun 2 04:19:17 CEST 2005
>> 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)
> Thanks Tim. The bizarre 'typo' appears to be caused by ad-blocking
> 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