[Tutor] telnetlib unable to cath gaierror

Sander Sweers sander.sweers at gmail.com
Sun Dec 28 20:07:41 CET 2008

On Sun, Dec 28, 2008 at 19:17, Steve Willoughby <steve at alchemy.com> wrote:
> On Sun, Dec 28, 2008 at 07:09:51PM +0100, Sander Sweers wrote:
>> I am having issues cathing exceptions from telnetlib. What I am doing is:
>> except gaierror:
>> Which gives me "NameError: name 'gaierror' is not defined" :-(
> This error message contains your clue.  If the name you're referencing is not defined, you usually forgot to either explicitly import it, or to name it with its namespace attached.

Looking more closely it is not an error from telnetlib. It is an error
from the socket module.

>        from telnetlib import gaierror

It works with import socket.

> then your try/except clause would be like:
>        except telnetlib.gaierror:

I can catch it now with socket.gaierror but I do not understand why
telnetlib does not raise an error instead. To me it would be more
logically that telnetlib catches this and raises an error. Now this
comes from a very novice programmer so I might be way off on this :-)

Another question, read_until can be passed a timeout. How would catch
if the timeout hit? It does not raise an error it afaics just returns
whatever it read till the timeout.


More information about the Tutor mailing list