gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749)

This commit is contained in:
Petr Viktorin
2025-10-30 12:14:17 +01:00
committed by GitHub
parent 134adb32e8
commit 75a1cbdd38

View 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)