Python Forum
telnetlib timeout - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: telnetlib timeout (/thread-21063.html)



telnetlib timeout - kerzol81 - Sep-12-2019

Hi,

I made this test script, to connect to a telnet server, it works, if there is data to read, but if nor or the server is not available the script never jumps to the exception. It looks to me that the timeout parameter does not have any effect.
I experimented with the EOFError that read_until method raises according to the telnetlib documentation as well, without success.

while True:
    try:
        print('connecting')
        c = telnetlib.Telnet(ip, port, timeout=1)
        print('reading')
        message = str(c.read_until(b'BBB'))
        print(message.strip('b'))
        connection.close()
    except Exception as e:
        print(e)
        time.sleep(5)
        pass
Any idea, please?

Thanks