Inconsistent socket.gethostbyname exceptions

Donn Cave donn at oz.net
Sat Dec 11 13:59:17 EST 1999


Quoth Ronald Hiller <ron at graburn.com>:
| 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?

Somewhere in between the two, I think.  It's a good question, too good
for me or apparently anyone else to have a good answer!  If it's not a
bug, certainly it's not a strong point of the runtime either.

I hope in some future version of Python, the exception will have more
reliable attributes.  I have no specific idea how that would actually
look, what attributes precisely I'm looking for, but I think if the
socket module ever gets the 1.5 OO exception treatment, like the posix
module did, that will probably help.  I wouldn't be surprised if this
is on the list of things to do, but there also might be room for someone
to contribute that change.

	Donn Cave, donn at oz.net



More information about the Python-list mailing list