[Python-checkins] [3.10] bpo-43564: preserve original exception in args of FTP URLError (GH-24938) (#98138)

orsenthil webhook-mailer at python.org
Mon Oct 10 02:37:11 EDT 2022


https://github.com/python/cpython/commit/1ae7abf6b2f410feee02286a1b2179f2c6e88abd
commit: 1ae7abf6b2f410feee02286a1b2179f2c6e88abd
branch: 3.10
author: Senthil Kumaran <senthil at python.org>
committer: orsenthil <senthilx at amazon.com>
date: 2022-10-09T23:36:51-07:00
summary:

[3.10] bpo-43564: preserve original exception in args of FTP URLError (GH-24938) (#98138)

* bpo-43564: preserve original error in args of FTP URLError

* Add NEWS blurb

Co-authored-by: Carl Meyer <carljm at instagram.com>.
(cherry picked from commit ad817cd5c44416da3752ebf9baf16d650703275c)

Co-authored-by: Carl Meyer <carl at oddbird.net>

Co-authored-by: Carl Meyer <carl at oddbird.net>

files:
A Misc/NEWS.d/next/Library/2022-10-09-12-12-38.gh-issue-87730.ClgP3f.rst
M Lib/urllib/request.py

diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 320163be63ad..76fdd719cdaa 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1579,8 +1579,7 @@ def ftp_open(self, req):
             headers = email.message_from_string(headers)
             return addinfourl(fp, headers, req.full_url)
         except ftplib.all_errors as exp:
-            exc = URLError('ftp error: %r' % exp)
-            raise exc.with_traceback(sys.exc_info()[2])
+            raise URLError(exp) from exp
 
     def connect_ftp(self, user, passwd, host, port, dirs, timeout):
         return ftpwrapper(user, passwd, host, port, dirs, timeout,
diff --git a/Misc/NEWS.d/next/Library/2022-10-09-12-12-38.gh-issue-87730.ClgP3f.rst b/Misc/NEWS.d/next/Library/2022-10-09-12-12-38.gh-issue-87730.ClgP3f.rst
new file mode 100644
index 000000000000..6c63fa4928c6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-10-09-12-12-38.gh-issue-87730.ClgP3f.rst
@@ -0,0 +1,3 @@
+Wrap network errors consistently in urllib FTP support, so the test suite
+doesn't fail when a network is available but the public internet is not
+reachable.



More information about the Python-checkins mailing list