[Tutor] help with telnet error

Chris Hallman challman at gmail.com
Wed Jan 17 15:21:38 CET 2007


I'm working on a program that telnets to multiple devices to test their
backup ISDN BRI connections. I'm trying to build in error recovery with
try/except logic, but I'm having trouble getting it to work. This first
example uses a host name that isn't in our DNS (yes, this does happen):

>>> import telnetlib
>>> host = "s3793ap01"
>>> telnetlib.Telnet(host)

Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    telnetlib.Telnet(host)
  File "c:\python25\lib\telnetlib.py", line 208, in __init__
    self.open(host, port)
  File "c:\python25\lib\telnetlib.py", line 225, in open
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
gaierror: (11001, 'getaddrinfo failed')
>>>
>>>
>>>
>>>
>>> try:
    telnetlib.Telnet(host)
except gaierror, e:
    print "error found", e




Traceback (most recent call last):
  File "<pyshell#16>", line 3, in <module>
    except gaierror, e:
NameError: name 'gaierror' is not defined
>>>
>>>
>>>
>>> try:
    telnetlib.Telnet(host)
except IOError, e:
    print "error found", e




Traceback (most recent call last):
  File "<pyshell#22>", line 2, in <module>
    telnetlib.Telnet(host)
  File "c:\python25\lib\telnetlib.py", line 208, in __init__
    self.open(host, port)
  File "c:\python25\lib\telnetlib.py", line 225, in open
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
gaierror: (11001, 'getaddrinfo failed')


As you can see, I'm not sure how to handle the error. Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070117/4b2cdc02/attachment.htm 


More information about the Tutor mailing list