Inconsistent socket.gethostbyname exceptions

Ronald Hiller ron at graburn.com
Wed Dec 8 21:27:45 EST 1999


I've noticed that the socket.gethostbyname function doesn't return the
same format of exceptions as other socket operations (like connect).
For example, a failed get hostbyname returns a simple string 'host not
found' whereas a failed connect returns a list (146, 'Connection
refused').

I've looked at socketmodule.c and noticed that gethostbyname puts
together it's own exception while connect calls PySocket_Err to pack up
errno with the string into a tuple.

Now, I understand that there is no errno value for 'host not found' and
synthesizing something may be a "bad thing".  However, testing
exceptions is somewhat tricky since the format apparently differs
between operations.  Now, if these are the only two cases, I guess it's
not so bad, but I worry (I admit to not having searched the source) that
there could be more cases with different formats.

Is this a bug, or am I getting excited about nothing?

Thanks,
Ron




More information about the Python-list mailing list