http
— modules HTTP¶
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.client
est un client HTTP bas niveau. Pour accéder à des ressources web, utiliser le module haut niveauurllib.request
Le module
http.server
contient des classes serveur HTTP basiques basées sursocketserver
Le module
http.cookies
contient des utilitaires liés à la gestion d'état HTTP via les cookiesLe module
http.cookiejar
fournit 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¶
Nouveau dans la version 3.5.
Sous-classe de
enum.IntEnum
qui 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/1.1 RFC 7231, Section 6.2.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.2.2 |
|
|
WebDAV RFC 2518, Section 10.1 |
|
|
An HTTP Status Code for Indicating Hints RFC 8297 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.6 |
|
|
HTTP/1.1 RFC 7233, Section 4.1 |
|
|
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/1.1 RFC 7231, Section 6.4.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.4 |
|
|
HTTP/1.1 RFC 7232, Section 4.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.7 |
|
|
Permanent Redirect RFC 7238, Section 3 (Expérimental) |
|
|
HTTP/1.1 RFC 7231, Section 6.5.1 |
|
|
HTTP/1.1 Authentication RFC 7235, Section 3.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.6 |
|
|
HTTP/1.1 Authentication RFC 7235, Section 3.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.7 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.8 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.9 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.10 |
|
|
HTTP/1.1 RFC 7232, Section 4.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.11 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.12 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.13 |
|
|
HTTP/1.1 Range Requests RFC 7233, Section 4.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.14 |
|
|
HTCPCP/1.0 RFC 2324, Section 2.3.2 |
|
|
HTTP/2 RFC 7540, Section 9.1.2 |
|
|
WebDAV RFC 4918, Section 11.2 |
|
|
WebDAV RFC 4918, Section 11.3 |
|
|
WebDAV RFC 4918, Section 11.4 |
|
|
Using Early Data in HTTP RFC 8470 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.15 |
|
|
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/1.1 RFC 7231, Section 6.6.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.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
.
Nouveau dans la version 3.8: Added 451 UNAVAILABLE_FOR_LEGAL_REASONS
status code.
Nouveau dans la version 3.9: Added 103 EARLY_HINTS
, 418 IM_A_TEAPOT
and 425 TOO_EARLY
status codes.
- class http.HTTPMethod¶
Nouveau dans la version 3.11.
A subclass of
enum.StrEnum
that 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:
Method |
Message |
Détails |
---|---|---|
|
|
HTTP/1.1 RFC 7231, Section 4.3.1 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.2 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.3 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.4 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.5 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.6 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.7 |
|
|
HTTP/1.1 RFC 7231, Section 4.3.8 |
|
|
HTTP/1.1 RFC 5789 |