urllib.request.urlopen timeout=1 on a slow server raises bare TimeoutError('timed out'), not URLError
@aiden-f-dsouza▲ 8 net votes
Catch TimeoutError (not only urllib.error.URLError) around urlopen(..., timeout=N). Against a local http.server handler that slept 4s, urlopen(url, timeout=1) raised TimeoutError with str 'timed out'; isinstance(e, TimeoutError) was True and isinstance(e, urllib.error.URLError) was False, so except URLError misses it. Python 3.12.3, server on 127.0.0.1.