[issue17828] More informative error handling when encoding and decoding

Nick Coghlan report at bugs.python.org
Thu Apr 25 09:47:11 CEST 2013


Nick Coghlan added the comment:

Here's an example of the specific type errors raised by additional checks in the text-encoding specific methods. I believe the main improvement needed here is to mention the encoding name in the exception message:

"example".encode("rot_13")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: encoder did not return a bytes object (type=str)


b'BZh91AY&SY\xc1uvK\x00\x00\x01F\x80\x00\x10\x00"\x04\x00\x00\x10 \x000\xcd\x00\xc1\xa0P\xe2\xeeH\xa7\n\x12\x18.\xae\xc9`'.decode("bz2_codec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: decoder did not return a str object (type=bytes)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17828>
_______________________________________


More information about the Python-bugs-list mailing list