New submission from Борис Верховский <boris.v...@gmail.com>:
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. ---------- components: Library (Lib) messages: 352813 nosy: boris priority: normal severity: normal status: open title: pickle.dump and load error message when file isn't opened in binary mode are not useful versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38226> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com