[issue32943] confusing error message for rot13 codec

Xiang Zhang report at bugs.python.org
Sun Feb 25 00:22:05 EST 2018


New submission from Xiang Zhang <angwerzx at 126.com>:

rot13 codec does a str translate operation. But it doesn't check the input type and then the error message would be quite confusing, especially for bytes:

>>> codecs.encode(b'abc', 'rot13')
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/rot_13.py", line 15, in encode
    return (input.translate(rot13_map), len(input))
TypeError: a bytes-like object is required, not 'dict'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: encoding with 'rot13' codec failed (TypeError: a bytes-like object is required, not 'dict')

----------
messages: 312775
nosy: serhiy.storchaka, xiang.zhang
priority: normal
severity: normal
status: open
title: confusing error message for rot13 codec
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32943>
_______________________________________


More information about the Python-bugs-list mailing list