21.11. http — HTTP modules¶
Source code: Lib/http/__init__.py
http is a package that collects several modules for working with the
HyperText Transfer Protocol:
http.clientis a low-level HTTP protocol client; for high-level URL opening useurllib.requesthttp.servercontains basic HTTP server classes based onsocketserverhttp.cookieshas utilities for implementing state management with cookieshttp.cookiejarprovides persistence of cookies
http is also a module that defines a number of HTTP status codes and
associated messages through the http.HTTPStatus enum:
-
class
http.HTTPStatus¶ New in version 3.5.
A subclass of
enum.IntEnumthat defines a set of HTTP status codes, reason phrases and long descriptions written in English.Usage:
>>> from http import HTTPStatus >>> HTTPStatus.OK <HTTPStatus.OK: 200> >>> HTTPStatus.OK == 200 True >>> http.HTTPStatus.OK.value 200 >>> HTTPStatus.OK.phrase 'OK' >>> HTTPStatus.OK.description 'Request fulfilled, document follows' >>> list(HTTPStatus) [<HTTPStatus.CONTINUE: 100>, <HTTPStatus.SWITCHING_PROTOCOLS: 101>, ...]
21.11.1. HTTP status codes¶
Supported, IANA-registered status codes available in
http.HTTPStatusare:Code
Enum Name
Details
100CONTINUEHTTP/1.1 RFC 7231, Section 6.2.1
101SWITCHING_PROTOCOLSHTTP/1.1 RFC 7231, Section 6.2.2
102PROCESSINGWebDAV RFC 2518, Section 10.1
200OKHTTP/1.1 RFC 7231, Section 6.3.1
201CREATEDHTTP/1.1 RFC 7231, Section 6.3.2
202ACCEPTEDHTTP/1.1 RFC 7231, Section 6.3.3
203NON_AUTHORITATIVE_INFORMATIONHTTP/1.1 RFC 7231, Section 6.3.4
204NO_CONTENTHTTP/1.1 RFC 7231, Section 6.3.5
205RESET_CONTENTHTTP/1.1 RFC 7231, Section 6.3.6
206PARTIAL_CONTENTHTTP/1.1 RFC 7233, Section 4.1
207MULTI_STATUSWebDAV RFC 4918, Section 11.1
208ALREADY_REPORTEDWebDAV Binding Extensions RFC 5842, Section 7.1 (Experimental)
226IM_USEDDelta Encoding in HTTP RFC 3229, Section 10.4.1
300MULTIPLE_CHOICESHTTP/1.1 RFC 7231, Section 6.4.1
301MOVED_PERMANENTLYHTTP/1.1 RFC 7231, Section 6.4.2
302FOUNDHTTP/1.1 RFC 7231, Section 6.4.3
303SEE_OTHERHTTP/1.1 RFC 7231, Section 6.4.4
304NOT_MODIFIEDHTTP/1.1 RFC 7232, Section 4.1
305USE_PROXYHTTP/1.1 RFC 7231, Section 6.4.5
307TEMPORARY_REDIRECTHTTP/1.1 RFC 7231, Section 6.4.7
308PERMANENT_REDIRECTPermanent Redirect RFC 7238, Section 3 (Experimental)
400BAD_REQUESTHTTP/1.1 RFC 7231, Section 6.5.1
401UNAUTHORIZEDHTTP/1.1 Authentication RFC 7235, Section 3.1
402PAYMENT_REQUIREDHTTP/1.1 RFC 7231, Section 6.5.2
403FORBIDDENHTTP/1.1 RFC 7231, Section 6.5.3
404NOT_FOUNDHTTP/1.1 RFC 7231, Section 6.5.4
405METHOD_NOT_ALLOWEDHTTP/1.1 RFC 7231, Section 6.5.5
406NOT_ACCEPTABLEHTTP/1.1 RFC 7231, Section 6.5.6
407PROXY_AUTHENTICATION_REQUIREDHTTP/1.1 Authentication RFC 7235, Section 3.2
408REQUEST_TIMEOUTHTTP/1.1 RFC 7231, Section 6.5.7
409CONFLICTHTTP/1.1 RFC 7231, Section 6.5.8
410GONEHTTP/1.1 RFC 7231, Section 6.5.9
411LENGTH_REQUIREDHTTP/1.1 RFC 7231, Section 6.5.10
412PRECONDITION_FAILEDHTTP/1.1 RFC 7232, Section 4.2
413REQUEST_ENTITY_TOO_LARGEHTTP/1.1 RFC 7231, Section 6.5.11
414REQUEST_URI_TOO_LONGHTTP/1.1 RFC 7231, Section 6.5.12
415UNSUPPORTED_MEDIA_TYPEHTTP/1.1 RFC 7231, Section 6.5.13
416REQUEST_RANGE_NOT_SATISFIABLEHTTP/1.1 Range Requests RFC 7233, Section 4.4
417EXPECTATION_FAILEDHTTP/1.1 RFC 7231, Section 6.5.14
422UNPROCESSABLE_ENTITYWebDAV RFC 4918, Section 11.2
423LOCKEDWebDAV RFC 4918, Section 11.3
424FAILED_DEPENDENCYWebDAV RFC 4918, Section 11.4
426UPGRADE_REQUIREDHTTP/1.1 RFC 7231, Section 6.5.15
428PRECONDITION_REQUIREDAdditional HTTP Status Codes RFC 6585
429TOO_MANY_REQUESTSAdditional HTTP Status Codes RFC 6585
431REQUEST_HEADER_FIELDS_TOO_LARGEAdditional HTTP Status Codes RFC 6585
500INTERNAL_SERVER_ERRORHTTP/1.1 RFC 7231, Section 6.6.1
501NOT_IMPLEMENTEDHTTP/1.1 RFC 7231, Section 6.6.2
502BAD_GATEWAYHTTP/1.1 RFC 7231, Section 6.6.3
503SERVICE_UNAVAILABLEHTTP/1.1 RFC 7231, Section 6.6.4
504GATEWAY_TIMEOUTHTTP/1.1 RFC 7231, Section 6.6.5
505HTTP_VERSION_NOT_SUPPORTEDHTTP/1.1 RFC 7231, Section 6.6.6
506VARIANT_ALSO_NEGOTIATESTransparent Content Negotiation in HTTP RFC 2295, Section 8.1 (Experimental)
507INSUFFICIENT_STORAGEWebDAV RFC 4918, Section 11.5
508LOOP_DETECTEDWebDAV Binding Extensions RFC 5842, Section 7.2 (Experimental)
510NOT_EXTENDEDAn HTTP Extension Framework RFC 2774, Section 7 (Experimental)
511NETWORK_AUTHENTICATION_REQUIREDAdditional HTTP Status Codes RFC 6585, Section 6
In order to preserve backwards compatibility, enum values are also present in the
http.clientmodule in the form of constants. The enum name is equal to the constant name (i.e.http.HTTPStatus.OKis also available ashttp.client.OK).
