<br>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):
<br><br>>>> import telnetlib<br>>>> host = "s3793ap01"<br>>>> telnetlib.Telnet(host)<br><br>Traceback (most recent call last):<br> File "<pyshell#30>", line 1, in <module>
<br> telnetlib.Telnet(host)<br> File "c:\python25\lib\telnetlib.py", line 208, in __init__<br> self.open(host, port)<br> File "c:\python25\lib\telnetlib.py", line 225, in open<br> for res in
socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):<br>gaierror: (11001, 'getaddrinfo failed')<br>>>> <br>>>> <br>>>> <br>>>> <br>>>> try:<br> telnetlib.Telnet(host)
<br>except gaierror, e:<br> print "error found", e<br><br><br> <br><br>Traceback (most recent call last):<br> File "<pyshell#16>", line 3, in <module><br> except gaierror, e:<br>NameError: name 'gaierror' is not defined
<br>>>> <br>>>> <br>>>> <br>>>> try:<br> telnetlib.Telnet(host)<br>except IOError, e:<br> print "error found", e<br><br><br> <br><br>Traceback (most recent call last):
<br> File "<pyshell#22>", line 2, in <module><br> telnetlib.Telnet(host)<br> File "c:\python25\lib\telnetlib.py", line 208, in __init__<br> self.open(host, port)<br> File "c:\python25\lib\telnetlib.py", line 225, in open
<br> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):<br>gaierror: (11001, 'getaddrinfo failed')<br><br><br>As you can see, I'm not sure how to handle the error. Any ideas?<br><br>