Question

I am trying to make a script, which connects to a server by telnet. I am using python and telnetlib. I have problems getting timeout to work. I want to use the optional timeout when connecting to host, so that I get an exception if the host isn't online.

I have read the python telnetlib documentation but I have no idea what's wrong with my code.

Here is my simple code:

import telnetlib

host = 'hostname'
tn = telnetlib.Telnet(host, 23, 5) # port 23, timeout 45secs
print 'Connecting to', host
tn.close()

And here is my error message:

Exception exceptions.AttributeError: "Telnet instance has no attribute 'sock'" in      <bound method Telnet.__del__ of <telnetlib.Telnet instance at 0x7f269864b8c0>> ignored
Traceback (most recent call last):
File "test2.py", line 7, in <module>
tn = telnetlib.Telnet(host, 23, 5)
TypeError: __init__() takes at most 3 arguments (4 given)
Was it helpful?

Solution

You probably aren't using python 2.6 or above. Quote from the docs:

Changed in version 2.6: timeout was added.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top