summaryrefslogtreecommitdiff
path: root/Lib/socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/socket.py')
-rw-r--r--Lib/socket.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 89fe36e7f9..004d6a9445 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")