[Tutor] telnetlib unable to cath gaierror

Sander Sweers sander.sweers at gmail.com
Sun Dec 28 19:09:51 CET 2008

Hello All,

I am having issues cathing exceptions from telnetlib. What I am doing is:

tc = telnetlib.Telnet()

except gaierror:
    print 'Invalid hostname'

Which gives me "NameError: name 'gaierror' is not defined" :-(

>From the interactive promt I see:

>>> tc = telnetlib.Telnet('abc')

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    tc = telnetlib.Telnet('blah')
  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')

So why can I not catch it with try/except?


More information about the Tutor mailing list