telnetlib.Telnet not catching OSError

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('', 22)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/", line 218, in __init__, port, timeout)
  File "/usr/lib/python3.8/", line 235, in open
    self.sock = socket.create_connection((host, port), timeout)
  File "/usr/lib/python3.8/", line 808, in create_connection
    raise err
  File "/usr/lib/python3.8/", line 796, in create_connection
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.

I suggest you open an issue on the bug tracker.