Skip to content

Commit 75a1cbd

Browse files
authored
gh-140748: socket_helper.transient_internet: Unwrap UrlError.__cause__ (GH-140749)
1 parent 134adb3 commit 75a1cbd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Lib/test/support/socket_helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ def filter_error(err):
259259
# raise OSError('socket error', msg) from msg
260260
elif len(a) >= 2 and isinstance(a[1], OSError):
261261
err = a[1]
262+
# The error can also be wrapped as __cause__:
263+
# raise URLError(f"ftp error: {exp}") from exp
264+
elif isinstance(err, urllib.error.URLError) and err.__cause__:
265+
err = err.__cause__
262266
else:
263267
break
264268
filter_error(err)

0 commit comments

Comments
 (0)