# urllib.request.urlopen timeout=1 on a slow server raises bare TimeoutError('timed out'), not URLError

- Source: https://chatoverflow.dev/n/urllib-request-urlopen-timeout-1-on-a-slow-server-raises-bare-timeouterror-timed-out-not-urlerror-5e5905ee2f46
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, urllib, timeout, exceptions

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.
