http --- HTTP modules¶
Code source : Lib/http/__init__.py
http est un paquet qui rassemble plusieurs modules servant à travailler avec le protocole HTTP (HyperText Transfer Procotol) :
Le module
http.clientest un client HTTP bas niveau. Pour accéder à des ressources web, utiliser le module haut niveauurllib.requestLe module
http.servercontient des classes serveur HTTP basiques basées sursocketserverLe module
http.cookiescontient des utilitaires liés à la gestion d'état HTTP via les cookiesLe module
http.cookiejarfournit un mécanisme de persistance des cookies
The http module also defines the following enums that help you work with http related code:
- class http.HTTPStatus¶
Ajouté dans la version 3.5.
Sous-classe de
enum.IntEnumqui définit un ensemble de codes d'état HTTP, messages explicatifs et descriptions complètes écrites en anglais.Utilisation :
>>> 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, ...]
Codes d'état HTTP¶
Supported,
IANA-registered status codes
available in http.HTTPStatus are:
Code |
Message |
Détails |
|---|---|---|
|
|
HTTP Semantics RFC 9110, Section 15.2.1 |
|
|
HTTP Semantics RFC 9110, Section 15.2.2 |
|
|
WebDAV RFC 2518, Section 10.1 |
|
|
An HTTP Status Code for Indicating Hints RFC 8297 |
|
|
HTTP Semantics RFC 9110, Section 15.3.1 |
|
|
HTTP Semantics RFC 9110, Section 15.3.2 |
|
|
HTTP Semantics RFC 9110, Section 15.3.3 |
|
|
HTTP Semantics RFC 9110, Section 15.3.4 |
|
|
HTTP Semantics RFC 9110, Section 15.3.5 |
|
|
HTTP Semantics RFC 9110, Section 15.3.6 |
|
|
HTTP Semantics RFC 9110, Section 15.3.7 |
|
|
WebDAV RFC 4918, Section 11.1 |
|
|
WebDAV Binding Extensions RFC 5842, Section 7.1 (Expérimental) |
|
|
Delta Encoding in HTTP RFC 3229, Section 10.4.1 |
|
|
HTTP Semantics RFC 9110, Section 15.4.1 |
|
|
HTTP Semantics RFC 9110, Section 15.4.2 |
|
|
HTTP Semantics RFC 9110, Section 15.4.3 |
|
|
HTTP Semantics RFC 9110, Section 15.4.4 |
|
|
HTTP Semantics RFC 9110, Section 15.4.5 |
|
|
HTTP Semantics RFC 9110, Section 15.4.6 |
|
|
HTTP Semantics RFC 9110, Section 15.4.8 |
|
|
HTTP Semantics RFC 9110, Section 15.4.9 |
|
|
HTTP Semantics RFC 9110, Section 15.5.1 |
|
|
HTTP Semantics RFC 9110, Section 15.5.2 |
|
|
HTTP Semantics RFC 9110, Section 15.5.3 |
|
|
HTTP Semantics RFC 9110, Section 15.5.4 |
|
|
HTTP Semantics RFC 9110, Section 15.5.5 |
|
|
HTTP Semantics RFC 9110, Section 15.5.6 |
|
|
HTTP Semantics RFC 9110, Section 15.5.7 |
|
|
HTTP Semantics RFC 9110, Section 15.5.8 |
|
|
HTTP Semantics RFC 9110, Section 15.5.9 |
|
|
HTTP Semantics RFC 9110, Section 15.5.10 |
|
|
HTTP Semantics RFC 9110, Section 15.5.11 |
|
|
HTTP Semantics RFC 9110, Section 15.5.12 |
|
|
HTTP Semantics RFC 9110, Section 15.5.13 |
|
|
HTTP Semantics RFC 9110, Section 15.5.14 |
|
|
HTTP Semantics RFC 9110, Section 15.5.15 |
|
|
HTTP Semantics RFC 9110, Section 15.5.16 |
|
|
HTTP Semantics RFC 9110, Section 15.5.17 |
|
|
HTTP Semantics RFC 9110, Section 15.5.18 |
|
|
HTCPCP/1.0 RFC 2324, Section 2.3.2 |
|
|
HTTP Semantics RFC 9110, Section 15.5.20 |
|
|
HTTP Semantics RFC 9110, Section 15.5.21 |
|
|
WebDAV RFC 4918, Section 11.3 |
|
|
WebDAV RFC 4918, Section 11.4 |
|
|
Using Early Data in HTTP RFC 8470 |
|
|
HTTP Semantics RFC 9110, Section 15.5.22 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
An HTTP Status Code to Report Legal Obstacles RFC 7725 |
|
|
HTTP Semantics RFC 9110, Section 15.6.1 |
|
|
HTTP Semantics RFC 9110, Section 15.6.2 |
|
|
HTTP Semantics RFC 9110, Section 15.6.3 |
|
|
HTTP Semantics RFC 9110, Section 15.6.4 |
|
|
HTTP Semantics RFC 9110, Section 15.6.5 |
|
|
HTTP Semantics RFC 9110, Section 15.6.6 |
|
|
Transparent Content Negotiation in HTTP RFC 2295, Section 8.1 (Expérimental) |
|
|
WebDAV RFC 4918, Section 11.5 |
|
|
WebDAV Binding Extensions RFC 5842, Section 7.2 (Expérimental) |
|
|
An HTTP Extension Framework RFC 2774, Section 7 (Expérimental) |
|
|
Codes d'état HTTP supplémentaires RFC 6585, Section 6 |
Dans le but de préserver la compatibilité descendante, les valeurs d'énumération sont aussi présentes dans le module http.client sous forme de constantes. Les noms de valeurs de l'énumération sont accessibles de deux manières : par exemple, le code HTTP 200 est accessible sous les noms http.HTTPStatus.OK et http.client.OK.
Modifié dans la version 3.7: Ajouté le code d'état 421 MISDIRECTED_REQUEST.
Ajouté dans la version 3.8: Added 451 UNAVAILABLE_FOR_LEGAL_REASONS status code.
Ajouté dans la version 3.9: Added 103 EARLY_HINTS, 418 IM_A_TEAPOT and 425 TOO_EARLY status codes.
Modifié dans la version 3.13: Implemented RFC9110 naming for status constants. Old constant names are preserved for
backwards compatibility: 413 REQUEST_ENTITY_TOO_LARGE, 414 REQUEST_URI_TOO_LONG,
416 REQUESTED_RANGE_NOT_SATISFIABLE and 422 UNPROCESSABLE_ENTITY.
HTTP status category¶
Ajouté dans la version 3.12.
The enum values have several properties to indicate the HTTP status category:
Property |
Indicates that |
Détails |
|---|---|---|
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
Utilisation :
>>> from http import HTTPStatus >>> HTTPStatus.OK.is_success True >>> HTTPStatus.OK.is_client_error False
- class http.HTTPMethod¶
Ajouté dans la version 3.11.
A subclass of
enum.StrEnumthat defines a set of HTTP methods and descriptions written in English.Utilisation :
>>> 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 methods¶
Supported,
IANA-registered methods
available in http.HTTPMethod are:
Méthode |
Message |
Détails |
|---|---|---|
|
|
HTTP Semantics RFC 9110, Section 9.3.1 |
|
|
HTTP Semantics RFC 9110, Section 9.3.2 |
|
|
HTTP Semantics RFC 9110, Section 9.3.3 |
|
|
HTTP Semantics RFC 9110, Section 9.3.4 |
|
|
HTTP Semantics RFC 9110, Section 9.3.5 |
|
|
HTTP Semantics RFC 9110, Section 9.3.6 |
|
|
HTTP Semantics RFC 9110, Section 9.3.7 |
|
|
HTTP Semantics RFC 9110, Section 9.3.8 |
|
|
HTTP/1.1 RFC 5789 |