If the Telnet
client tries to create connection to an unreachable IP address, the underlying implementation of socket library rasies OSError: [Errno 113] No route to host
.
Either this error should be handled by telnetlib
or it should be explicitly mentioned in the documentation.
The documentation clearly mentions that telnetlib.Telnet.write
may raise OSError
. It should do same for telnetlib.Telnet.opeen
or any other method that can potentially raise this error.
Here’s a sample code:
import telnetlib
telnetlib.Telnet('192.168.54.1', 22)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/telnetlib.py", line 218, in __init__
self.open(host, port, timeout)
File "/usr/lib/python3.8/telnetlib.py", line 235, in open
self.sock = socket.create_connection((host, port), timeout)
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
OSError: [Errno 113] No route to host
It will be really helpful to know if this issue is worthy to be put on Python’s bug tracker.
Thanks!