[3.14] gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749) (GH-141505)

(cherry picked from commit 75a1cbdd38)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-11-13 13:58:37 +01:00 committed by GitHub
parent 7b8c257933
commit 55cf97d8dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -259,6 +259,10 @@ def filter_error(err):
# 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)