Skip to content

Commit

Permalink
gh-101536: [docs] Improve attributes of urllib.error.HTTPError (#10…
Browse files Browse the repository at this point in the history
…1612)

* gh-101536: [docs] Improve attributes of `urllib.error.HTTPError`

* Address review
  • Loading branch information
sobolevn authored Feb 18, 2023
1 parent 89413bb commit af446bb
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit af446bb

Please sign in to comment.