diff options
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index 9ed2de9132..bd364e70db 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -548,8 +548,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 @@ -562,8 +562,12 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, sock.connect(sa) return sock - except error, msg: + 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") |