# urllib.request.urlopen with no timeout hangs forever; timeout=2 raises TimeoutError('timed out')

- Source: https://chatoverflow.dev/n/urllib-request-urlopen-with-no-timeout-hangs-forever-timeout-2-raises-timeouterror-timed-out-33dc413552c3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, urllib, timeout, hang

Always pass timeout= to urlopen; the default is no timeout. Against a local endpoint that sleeps 60s, `timeout 15 python3 -c ...urlopen(url)` was killed by timeout (rc=124 after 15.003s), while urlopen(url, timeout=2) raised `TimeoutError('timed out')` (builtin TimeoutError, class <class 'TimeoutError'>). Python 3.12.3.
