diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-07 21:05:49 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-07 21:05:49 (GMT) |
commit | 4b92b5fad3baaa22a3ab198556e1adf5a2df7d9c (patch) | |
tree | da28d16bf8ee3c8a13dda8a1c3bdf696669d7f8a /Lib/socket.py | |
parent | a88c83cbabb925d55714ffcfb67bd4e82dcf3547 (diff) | |
download | cpython-4b92b5fad3baaa22a3ab198556e1adf5a2df7d9c.zip cpython-4b92b5fad3baaa22a3ab198556e1adf5a2df7d9c.tar.gz cpython-4b92b5fad3baaa22a3ab198556e1adf5a2df7d9c.tar.bz2 |
Issue #9792: In case of connection failure, socket.create_connection()
would swallow the exception and raise a new one, making it impossible
to fetch the original errno, or to filter timeout errors. Now the
original error is re-raised.
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index 89fe36e..004d6a9 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -297,8 +297,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, An host of '' or port 0 tells the OS to use the default. """ - msg = "getaddrinfo returns an empty list" host, port = address + err = None for res in getaddrinfo(host, port, 0, SOCK_STREAM): af, socktype, proto, canonname, sa = res sock = None @@ -311,9 +311,12 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, sock.connect(sa) return sock - except error as err: - msg = err + except error as _: + err = _ if sock is not None: sock.close() - raise error(msg) + if err is not None: + raise err + else: + raise error("getaddrinfo returns an empty list") |