diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2012-12-17 13:20:27 (GMT) |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2012-12-17 13:20:27 (GMT) |
commit | fc3278802c51bc8d56bc8a26cc9f95e4f6cfb5bd (patch) | |
tree | f4c0352003d557b7e69d16691807983389594977 /Lib/ftplib.py | |
parent | f635172c7222a6a6e1e2aa78c8ad987ec06cfded (diff) | |
download | cpython-fc3278802c51bc8d56bc8a26cc9f95e4f6cfb5bd.zip cpython-fc3278802c51bc8d56bc8a26cc9f95e4f6cfb5bd.tar.gz cpython-fc3278802c51bc8d56bc8a26cc9f95e4f6cfb5bd.tar.bz2 |
Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka)
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r-- | Lib/ftplib.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 8e53023..94237ca 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -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 |