Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch...
authorGiampaolo Rodola' <g.rodola@gmail.com>
Mon, 17 Dec 2012 13:20:27 +0000 (14:20 +0100)
committerGiampaolo Rodola' <g.rodola@gmail.com>
Mon, 17 Dec 2012 13:20:27 +0000 (14:20 +0100)
Lib/ftplib.py
Misc/NEWS

index 8e5302327030837432321de73026ee7aed41d858..94237caf214522615e77d31d9fbb420c1c058a78 100644 (file)
@@ -284,20 +284,24 @@ class FTP:
 
     def makeport(self):
         '''Create a new socket and send a PORT command for it.'''
-        msg = "getaddrinfo returns an empty list"
+        err = None
         sock = None
         for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
             af, socktype, proto, canonname, sa = res
             try:
                 sock = socket.socket(af, socktype, proto)
                 sock.bind(sa)
-            except socket.error as msg:
+            except socket.error as err:
                 if sock:
                     sock.close()
                 sock = None
                 continue
             break
-        if not sock:
+        if sock is None:
+            if err is not None:
+                raise err
+            else:
+                raise socket.error("getaddrinfo returns an empty list")
             raise socket.error(msg)
         sock.listen(1)
         port = sock.getsockname()[1] # Get proper port
index 9e172cac28e22339bd392069f58c1446a277e827..2b50cbbccef12874851d772a3987314ec532d4f7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -179,6 +179,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
+  (patch by Serhiy Storchaka)
+
 - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the
   pattern contains a wildcard in the drive or UNC path.  Patch by Serhiy
   Storchaka.