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.

Author boris
Recipients boris
Date 2019-09-19.20:31:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568925061.22.0.28448935108.issue38226@roundup.psfhosted.org>
In-reply-to
Content
pickle.load() and pickle.dump() take a file object as an argument. That file object must be opened in binary mode ("rb" or "wb"). If it's not, pickle raises a confusing error message.

When pickle.dump()'ing to a file opened in "w" mode instead of "wb" mode it'll raise a TypeError:


TypeError: write() argument must be str, not bytes


I thought it might be getting this because I was pickling bytes objects. 

For pickle.load()'ing from a file opened in "r" mode instead of "rb" mode, it'll raise a UnicodeDecodeError


UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte


There are a couple pages on the internet (just search "pickle" followed by either error message) with people being confused about this. 

pickle should catch these errors and report something more useful.
History
Date User Action Args
2019-09-19 20:31:01borissetrecipients: + boris
2019-09-19 20:31:01borissetmessageid: <1568925061.22.0.28448935108.issue38226@roundup.psfhosted.org>
2019-09-19 20:31:01borislinkissue38226 messages
2019-09-19 20:31:00boriscreate