Python Forum

Full Version: telnetlib timeout
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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