Skip to content

Commit 0068b4a

Browse files
miss-islingtonorsenthilclaude
authored
[3.14] gh-57945: Document exceptions not wrapped by urlopen() (GH-160830) (#160831)
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 7b05045 commit 0068b4a

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
@@ -72,6 +72,16 @@ The :mod:`!urllib.request` module defines the following functions:
7272

7373
Raises :exc:`~urllib.error.URLError` on protocol errors.
7474

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

0 commit comments

Comments
 (0)