Skip to content

Commit 2e3437c

Browse files
orsenthilclaude
authored andcommitted
gh-57945: Document exceptions not wrapped by urlopen() (GH-160830)
Exceptions raised while reading or parsing the HTTP response, such as http.client.HTTPException subclasses and OSError subclasses like TimeoutError, propagate from urlopen() without being wrapped in URLError. Document this, and that ValueError is raised for an invalid URL. (cherry picked from commit 87f8c0d) Co-authored-by: Senthil Kumaran <senthil@python.org> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4a79b92 commit 2e3437c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎Doc/library/urllib.request.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ The :mod:`!urllib.request` module defines the following functions:
6868

6969
Raises :exc:`~urllib.error.URLError` on protocol errors.
7070

71+
Exceptions raised while reading or parsing an HTTP response are not
72+
wrapped in :exc:`~urllib.error.URLError` and propagate unchanged.
73+
These include subclasses of :exc:`http.client.HTTPException`, such as
74+
:exc:`~http.client.BadStatusLine` for a malformed status line, and
75+
subclasses of :exc:`OSError`, such as :exc:`TimeoutError` if the server
76+
does not respond within *timeout* seconds, or
77+
:exc:`~http.client.RemoteDisconnected` if the server closes the
78+
connection without sending a response. :exc:`ValueError` is raised if
79+
*url* is not a valid URL.
80+
7181
Note that ``None`` may be returned if no handler handles the request (though
7282
the default installed global :class:`OpenerDirector` uses
7383
:class:`UnknownHandler` to ensure this never happens).

0 commit comments

Comments
 (0)