Issue #23881: urllib.ftpwrapper constructor now closes the socket if the FTP
connection failed.
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 2408cb8..9f972e3 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -871,7 +871,11 @@
self.timeout = timeout
self.refcount = 0
self.keepalive = persistent
- self.init()
+ try:
+ self.init()
+ except:
+ self.close()
+ raise
def init(self):
import ftplib
diff --git a/Misc/NEWS b/Misc/NEWS
index c9febc7..3f24df1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,9 @@
Library
-------
+- Issue #23881: urllib.ftpwrapper constructor now closes the socket if the FTP
+ connection failed.
+
- Issue #15133: _tkinter.tkapp.getboolean() now supports long and Tcl_Obj and
always returns bool. tkinter.BooleanVar now validates input values (accepted
bool, int, long, str, unicode, and Tcl_Obj). tkinter.BooleanVar.get() now