]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749)
authorPetr Viktorin <encukou@gmail.com>
Thu, 30 Oct 2025 11:14:17 +0000 (12:14 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Oct 2025 11:14:17 +0000 (12:14 +0100)
Lib/test/support/socket_helper.py

index 87941ee1791b4e795b188f124bd7cde1551f58de..a41e487f3e4bc52012425e30eab9b430a3b3a7ab 100644 (file)
@@ -259,6 +259,10 @@ def transient_internet(resource_name, *, timeout=_NOT_SET, errnos=()):
             #        raise OSError('socket error', msg) from msg
             elif len(a) >= 2 and isinstance(a[1], OSError):
                 err = a[1]
+            # The error can also be wrapped as __cause__:
+            #    raise URLError(f"ftp error: {exp}") from exp
+            elif isinstance(err, urllib.error.URLError) and err.__cause__:
+                err = err.__cause__
             else:
                 break
         filter_error(err)