[Bug 1154599] Re: dns lookup failure raises socket.error not socket.gaierror
Barry Warsaw
1154599 at bugs.launchpad.net
Tue Apr 2 19:02:11 UTC 2013
The problem is that getaddrinfo() returns different error codes on
Ubuntu.
On Wheezy, getaddrinfo() returns -2 with errno set to 2 (ENOENT). On
Raring, getaddrinfo() returns -11 (EAI_SYSTEM) with errno also set to 2
(ENOENT). Python has this bit of code to set the error type based on
the return value of getaddrinfo() -- see Modules/socketmodule.c:
static PyObject *
set_gaierror(int error)
{
PyObject *v;
#ifdef EAI_SYSTEM
/* EAI_SYSTEM is not available on Windows XP. */
if (error == EAI_SYSTEM)
return set_error();
#endif
#ifdef HAVE_GAI_STRERROR
v = Py_BuildValue("(is)", error, gai_strerror(error));
#else
v = Py_BuildValue("(is)", error, "getaddrinfo failed");
#endif
if (v != NULL) {
PyErr_SetObject(socket_gaierror, v);
Py_DECREF(v);
}
return NULL;
}
So now it should be obvious why a different error type is getting raised
in Python (i.e. socket.error vs socket.gaierror). This is likely a
change in glibc's getaddrinfo() and nothing to do with Python.
Wheezy has libc6 2.13-38, Raring has libc6 2.17-0ubuntu4
** Bug watch added: Sourceware.org Bugzilla #15272
http://sourceware.org/bugzilla/show_bug.cgi?id=15272
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to python2.7 in Ubuntu.
https://bugs.launchpad.net/bugs/1154599
Title:
dns lookup failure raises socket.error not socket.gaierror
Status in Python:
New
Status in “python2.7” package in Ubuntu:
New
Bug description:
$ cat lookup.py
#!/usr/bin/python
import sys, socket
names = ["slashdot.org", "foooooooooowhizzzzzzzz.com"]
if len(sys.argv) > 1:
names = sys.argv[1:]
for iname in names:
try:
result = socket.getaddrinfo(iname, None, 0, 0, socket.SOCK_STREAM,
socket.AI_CANONNAME)
for (fam, stype, proto, cname, sockaddr) in result:
sys.stdout.write("cname=%s, sockaddr=%s\n" % (cname, sockaddr))
except socket.gaierror as error:
sys.stderr.write("%s failed lookup" % iname)
$ python2.7 lookup.py
cname=slashdot.org, sockaddr=('216.34.181.45', 0)
Traceback (most recent call last):
File "/tmp/x.py", line 10, in <module>
socket.AI_CANONNAME)
socket.error: [Errno 2] No such file or directory
shell returned 1
$ dpkg -S /usr/bin/python2.7
python2.7-minimal: /usr/bin/python2.7
$ dpkg-query --show python2.7-minimal
python2.7-minimal 2.7.3-16ubuntu1
This is a behavioral change from quantal (2.7.3-5ubuntu4).
ProblemType: Bug
DistroRelease: Ubuntu 13.04
Package: python 2.7.3-10ubuntu5
ProcVersionSignature: Ubuntu 3.5.0-21.32-generic 3.5.7.1
Uname: Linux 3.5.0-21-generic x86_64
ApportVersion: 2.9.1-0ubuntu1
Architecture: amd64
Date: Wed Mar 13 09:52:55 2013
EcryptfsInUse: Yes
InstallationDate: Installed on 2011-10-19 (511 days ago)
InstallationMedia: Ubuntu 11.10 "Oneiric Ocelot" - Release amd64 (20111012)
MarkForUpload: True
ProcEnviron:
TERM=xterm
PATH=(custom, no user)
XDG_RUNTIME_DIR=<set>
LANG=en_US.UTF-8
SHELL=/bin/bash
SourcePackage: python-defaults
UpgradeStatus: Upgraded to raring on 2013-01-07 (64 days ago)
To manage notifications about this bug go to:
https://bugs.launchpad.net/python/+bug/1154599/+subscriptions
More information about the foundations-bugs
mailing list