[Tutor] help with telnet error
Kent Johnson
kent37 at tds.net
Wed Jan 17 15:37:48 CET 2007
Chris Hallman wrote:
>
> 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
gaierror is defined in the socket module. Add
import socket
then use
except socket.gaierror, e:
Kent
More information about the Tutor
mailing list