Skip to content

gh-101536: [docs] Improve attributes of urllib.error.HTTPError #101612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Doc/library/urllib.error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate:
of :exc:`IOError`.


.. exception:: HTTPError
.. exception:: HTTPError(url, code, msg, hdrs, fp)

Though being an exception (a subclass of :exc:`URLError`), an
:exc:`HTTPError` can also function as a non-exceptional file-like return
value (the same thing that :func:`~urllib.request.urlopen` returns). This
is useful when handling exotic HTTP errors, such as requests for
authentication.

.. attribute:: url

Contains the request URL.
An alias for *filename* attribute.

.. attribute:: code

An HTTP status code as defined in :rfc:`2616`. This numeric value corresponds
Expand All @@ -48,14 +53,20 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate:
.. attribute:: reason

This is usually a string explaining the reason for this error.
An alias for *msg* attribute.

.. attribute:: headers

The HTTP response headers for the HTTP request that caused the
:exc:`HTTPError`.
An alias for *hdrs* attribute.

.. versionadded:: 3.4

.. attribute:: fp

A file-like object where the HTTP error body can be read from.

.. exception:: ContentTooShortError(msg, content)

This exception is raised when the :func:`~urllib.request.urlretrieve`
Expand Down