[New-bugs-announce] [issue29621] telnetlib.Telnet.write gives confusing error message when a string is passed in
John Hagen
report at bugs.python.org
Wed Feb 22 11:35:21 EST 2017
New submission from John Hagen:
I was recently helping someone learn Python 3 from Python 2 and they were confused by error resulting from the following easy-to-make mistake:
import telnetlib
tn = telnetlib.Telnet('localhost')
tn.write('hello')
Traceback (most recent call last):
File "/Users/user/PycharmProjects/python-test/main.py", line 4, in <module>
tn.write('hello')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/telnetlib.py", line 287, in write
if IAC in buffer:
TypeError: 'in <string>' requires string as left operand, not bytes
What is confusing is that the solution is to pass in `bytes`, not a `str`, but the place where this manifests is in an `in` operator with the first argument as a `bytes` (telnetlib.IAC).
Perhaps a simple isinstance(buffer, bytes) could be used to throw a `TypeError` or something a bit more helpful.
It also doesn't help that for some reason Googling "python telnet" only seems to bring up the Python 2 docs link, rather than Python 3 or both.
----------
components: Library (Lib)
messages: 288371
nosy: John Hagen
priority: normal
severity: normal
status: open
title: telnetlib.Telnet.write gives confusing error message when a string is passed in
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29621>
_______________________________________
More information about the New-bugs-announce
mailing list