> **Источник:** https://python-all.ru/3.11/library/http.html
>
> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.

---

# [`http`](https://python-all.ru/3.11/library/http.html#module-http) – модули HTTP

**Исходный код:** [Lib/http/\_\_init\_\_.py](https://python-all.ru/src/3.11/Lib/http/__init__.py)

---

[`http`](https://python-all.ru/3.11/library/http.html#module-http) – пакет, объединяющий несколько модулей для работы с протоколом передачи гипертекста (HTTP):

- [`http.client`](https://python-all.ru/3.11/library/http.client.html#module-http.client) – низкоуровневый клиент протокола HTTP; для открытия URL на высоком уровне используйте [`urllib.request`](https://python-all.ru/3.11/library/urllib.request.html#module-urllib.request)
- [`http.server`](https://python-all.ru/3.11/library/http.server.html#module-http.server) содержит базовые классы HTTP-сервера на основе [`socketserver`](https://python-all.ru/3.11/library/socketserver.html#module-socketserver)
- [`http.cookies`](https://python-all.ru/3.11/library/http.cookies.html#module-http.cookies) содержит утилиты для реализации управления состоянием с помощью куки
- [`http.cookiejar`](https://python-all.ru/3.11/library/http.cookiejar.html#module-http.cookiejar) обеспечивает сохранение куки

Модуль [`http`](https://python-all.ru/3.11/library/http.html#module-http) также определяет следующие перечисления, которые помогают работать с кодом, связанным с HTTP:

#### `class http.HTTPStatus`

Новое в версии 3.5.

Подкласс [`enum.IntEnum`](https://python-all.ru/3.11/library/enum.html#enum.IntEnum), определяющий набор HTTP-статусов, поясняющих фраз и подробных описаний на английском языке.

Использование:

```python
>>> from http import HTTPStatus
>>> HTTPStatus.OK
HTTPStatus.OK
>>> HTTPStatus.OK == 200
True
>>> HTTPStatus.OK.value
200
>>> HTTPStatus.OK.phrase
'OK'
>>> HTTPStatus.OK.description
'Request fulfilled, document follows'
>>> list(HTTPStatus)
[HTTPStatus.CONTINUE, HTTPStatus.SWITCHING_PROTOCOLS, ...]
```

## Коды состояния HTTP

Поддерживаемые [зарегистрированные IANA коды состояния](https://python-all.ru/3.11/library/http.html), доступные в [`http.HTTPStatus`](https://python-all.ru/3.11/library/http.html#http.HTTPStatus):

| Код | Имя перечисления | Подробности |
| --- | --- | --- |
| `100` | `CONTINUE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.2.1 |
| `101` | `SWITCHING_PROTOCOLS` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.2.2 |
| `102` | `PROCESSING` | WebDAV [**RFC 2518**](https://python-all.ru/3.11/library/http.html), раздел 10.1 |
| `103` | `EARLY_HINTS` | Код состояния HTTP для указания подсказок [**RFC 8297**](https://python-all.ru/3.11/library/http.html) |
| `200` | `OK` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.1 |
| `201` | `CREATED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.2 |
| `202` | `ACCEPTED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.3 |
| `203` | `NON_AUTHORITATIVE_INFORMATION` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.4 |
| `204` | `NO_CONTENT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.5 |
| `205` | `RESET_CONTENT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.3.6 |
| `206` | `PARTIAL_CONTENT` | HTTP/1.1 [**RFC 7233**](https://python-all.ru/3.11/library/http.html), раздел 4.1 |
| `207` | `MULTI_STATUS` | WebDAV [**RFC 4918**](https://python-all.ru/3.11/library/http.html), раздел 11.1 |
| `208` | `ALREADY_REPORTED` | Расширения привязки WebDAV [**RFC 5842**](https://python-all.ru/3.11/library/http.html), раздел 7.1 (экспериментальный) |
| `226` | `IM_USED` | Дельта-кодирование в HTTP [**RFC 3229**](https://python-all.ru/3.11/library/http.html), раздел 10.4.1 |
| `300` | `MULTIPLE_CHOICES` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.1 |
| `301` | `MOVED_PERMANENTLY` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.2 |
| `302` | `FOUND` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.3 |
| `303` | `SEE_OTHER` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.4 |
| `304` | `NOT_MODIFIED` | HTTP/1.1 [**RFC 7232**](https://python-all.ru/3.11/library/http.html), раздел 4.1 |
| `305` | `USE_PROXY` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.5 |
| `307` | `TEMPORARY_REDIRECT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.4.7 |
| `308` | `PERMANENT_REDIRECT` | Постоянное перенаправление [**RFC 7238**](https://python-all.ru/3.11/library/http.html), раздел 3 (экспериментальный) |
| `400` | `BAD_REQUEST` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.1 |
| `401` | `UNAUTHORIZED` | HTTP/1.1 аутентификация [**RFC 7235**](https://python-all.ru/3.11/library/http.html), раздел 3.1 |
| `402` | `PAYMENT_REQUIRED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.2 |
| `403` | `FORBIDDEN` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.3 |
| `404` | `NOT_FOUND` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.4 |
| `405` | `METHOD_NOT_ALLOWED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.5 |
| `406` | `NOT_ACCEPTABLE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.6 |
| `407` | `PROXY_AUTHENTICATION_REQUIRED` | HTTP/1.1 аутентификация [**RFC 7235**](https://python-all.ru/3.11/library/http.html), раздел 3.2 |
| `408` | `REQUEST_TIMEOUT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.7 |
| `409` | `CONFLICT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.8 |
| `410` | `GONE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.9 |
| `411` | `LENGTH_REQUIRED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.10 |
| `412` | `PRECONDITION_FAILED` | HTTP/1.1 [**RFC 7232**](https://python-all.ru/3.11/library/http.html), раздел 4.2 |
| `413` | `REQUEST_ENTITY_TOO_LARGE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.11 |
| `414` | `REQUEST_URI_TOO_LONG` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.12 |
| `415` | `UNSUPPORTED_MEDIA_TYPE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.13 |
| `416` | `REQUESTED_RANGE_NOT_SATISFIABLE` | HTTP/1.1 запросы диапазона [**RFC 7233**](https://python-all.ru/3.11/library/http.html), раздел 4.4 |
| `417` | `EXPECTATION_FAILED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.14 |
| `418` | `IM_A_TEAPOT` | HTCPCP/1.0 [**RFC 2324**](https://python-all.ru/3.11/library/http.html), Раздел 2.3.2 |
| `421` | `MISDIRECTED_REQUEST` | HTTP/2 [**RFC 7540**](https://python-all.ru/3.11/library/http.html), раздел 9.1.2 |
| `422` | `UNPROCESSABLE_ENTITY` | WebDAV [**RFC 4918**](https://python-all.ru/3.11/library/http.html), раздел 11.2 |
| `423` | `LOCKED` | WebDAV [**RFC 4918**](https://python-all.ru/3.11/library/http.html), Раздел 11.3 |
| `424` | `FAILED_DEPENDENCY` | WebDAV [**RFC 4918**](https://python-all.ru/3.11/library/http.html), Раздел 11.4 |
| `425` | `TOO_EARLY` | Использование ранних данных в HTTP [**RFC 8470**](https://python-all.ru/3.11/library/http.html) |
| `426` | `UPGRADE_REQUIRED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.5.15 |
| `428` | `PRECONDITION_REQUIRED` | Дополнительные коды состояния HTTP [**RFC 6585**](https://python-all.ru/3.11/library/http.html) |
| `429` | `TOO_MANY_REQUESTS` | Дополнительные коды состояния HTTP [**RFC 6585**](https://python-all.ru/3.11/library/http.html) |
| `431` | `REQUEST_HEADER_FIELDS_TOO_LARGE` | Дополнительные коды состояния HTTP [**RFC 6585**](https://python-all.ru/3.11/library/http.html) |
| `451` | `UNAVAILABLE_FOR_LEGAL_REASONS` | Код состояния HTTP для сообщения о юридических препятствиях [**RFC 7725**](https://python-all.ru/3.11/library/http.html) |
| `500` | `INTERNAL_SERVER_ERROR` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.1 |
| `501` | `NOT_IMPLEMENTED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.2 |
| `502` | `BAD_GATEWAY` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.3 |
| `503` | `SERVICE_UNAVAILABLE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.4 |
| `504` | `GATEWAY_TIMEOUT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.5 |
| `505` | `HTTP_VERSION_NOT_SUPPORTED` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 6.6.6 |
| `506` | `VARIANT_ALSO_NEGOTIATES` | Прозрачное согласование содержимого в HTTP [**RFC 2295**](https://python-all.ru/3.11/library/http.html), раздел 8.1 (экспериментальный) |
| `507` | `INSUFFICIENT_STORAGE` | WebDAV [**RFC 4918**](https://python-all.ru/3.11/library/http.html), раздел 11.5 |
| `508` | `LOOP_DETECTED` | Расширения привязки WebDAV [**RFC 5842**](https://python-all.ru/3.11/library/http.html), раздел 7.2 (экспериментальный) |
| `510` | `NOT_EXTENDED` | Расширяемая структура HTTP [**RFC 2774**](https://python-all.ru/3.11/library/http.html), раздел 7 (экспериментальный) |
| `511` | `NETWORK_AUTHENTICATION_REQUIRED` | Дополнительные коды состояния HTTP [**RFC 6585**](https://python-all.ru/3.11/library/http.html), раздел 6 |

Для сохранения обратной совместимости значения перечисления также присутствуют в модуле [`http.client`](https://python-all.ru/3.11/library/http.client.html#module-http.client) в виде констант. Имя перечисления совпадает с именем константы (т.е. `http.HTTPStatus.OK` также доступно как `http.client.OK`).

Изменено в версии 3.7: Добавлен код состояния `421 MISDIRECTED_REQUEST`.

Новое в версии 3.8: Добавлен код состояния `451 UNAVAILABLE_FOR_LEGAL_REASONS`.

Новое в версии 3.9: Добавлены коды состояния `103 EARLY_HINTS`, `418 IM_A_TEAPOT` и `425 TOO_EARLY`.

#### `class http.HTTPMethod`

Новое в версии 3.11.

Подкласс [`enum.StrEnum`](https://python-all.ru/3.11/library/enum.html#enum.StrEnum), определяющий набор HTTP-методов и описаний на английском языке.

Использование:

```python
>>> from http import HTTPMethod
>>>
>>> HTTPMethod.GET
<HTTPMethod.GET>
>>> HTTPMethod.GET == 'GET'
True
>>> HTTPMethod.GET.value
'GET'
>>> HTTPMethod.GET.description
'Retrieve the target.'
>>> list(HTTPMethod)
[<HTTPMethod.CONNECT>,
 <HTTPMethod.DELETE>,
 <HTTPMethod.GET>,
 <HTTPMethod.HEAD>,
 <HTTPMethod.OPTIONS>,
 <HTTPMethod.PATCH>,
 <HTTPMethod.POST>,
 <HTTPMethod.PUT>,
 <HTTPMethod.TRACE>]
```

## Методы HTTP

Поддерживаемые, [зарегистрированные в IANA методы](https://python-all.ru/3.11/library/http.html) доступные в [`http.HTTPMethod`](https://python-all.ru/3.11/library/http.html#http.HTTPMethod):

| Метод | Имя перечисления | Подробности |
| --- | --- | --- |
| `GET` | `GET` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.1 |
| `HEAD` | `HEAD` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.2 |
| `POST` | `POST` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.3 |
| `PUT` | `PUT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.4 |
| `DELETE` | `DELETE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.5 |
| `CONNECT` | `CONNECT` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.6 |
| `OPTIONS` | `OPTIONS` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.7 |
| `TRACE` | `TRACE` | HTTP/1.1 [**RFC 7231**](https://python-all.ru/3.11/library/http.html), раздел 4.3.8 |
| `PATCH` | `PATCH` | HTTP/1.1 [**RFC 5789**](https://python-all.ru/3.11/library/http.html) |
