Message288371
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. |
|
Date |
User |
Action |
Args |
2017-02-22 16:35:21 | John Hagen | set | recipients:
+ John Hagen |
2017-02-22 16:35:21 | John Hagen | set | messageid: <1487781321.4.0.45367640243.issue29621@psf.upfronthosting.co.za> |
2017-02-22 16:35:21 | John Hagen | link | issue29621 messages |
2017-02-22 16:35:21 | John Hagen | create | |
|