From: Petr Viktorin Date: Thu, 30 Oct 2025 11:14:17 +0000 (+0100) Subject: gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75a1cbdd38b142b359849eae16a2ecc12f6b3881;p=thirdparty%2FPython%2Fcpython.git gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749) --- diff --git a/Lib/test/support/socket_helper.py b/Lib/test/support/socket_helper.py index 87941ee1791b..a41e487f3e4b 100644 --- a/Lib/test/support/socket_helper.py +++ b/Lib/test/support/socket_helper.py @@ -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)