### 导航
- [索引](../genindex.xhtml "总目录")
- [模块](../py-modindex.xhtml "Python 模块索引") |
- [下一页](http.client.xhtml "http.client --- HTTP协议客户端") |
- [上一页](urllib.robotparser.xhtml "urllib.robotparser --- Parser for robots.txt") |
- ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png)
- [Python](https://www.python.org/) »
- zh\_CN 3.7.3 [文档](../index.xhtml) »
- [Python 标准库](index.xhtml) »
- [互联网协议和支持](internet.xhtml) »
- $('.inline-search').show(0); |
# [`http`](#module-http "http: HTTP status codes and messages") --- HTTP 模块
**源代码:** [Lib/http/\_\_init\_\_.py](https://github.com/python/cpython/tree/3.7/Lib/http/__init__.py) \[https://github.com/python/cpython/tree/3.7/Lib/http/\_\_init\_\_.py\]
- - - - - -
[`http`](#module-http "http: HTTP status codes and messages") 是一个包,它收集了多个用于处理超文本传输协议的模块:
- [`http.client`](http.client.xhtml#module-http.client "http.client: HTTP and HTTPS protocol client (requires sockets).") 是一个低层级的 HTTP 协议客户端;对于高层级的 URL 访问请使用 [`urllib.request`](urllib.request.xhtml#module-urllib.request "urllib.request: Extensible library for opening URLs.")
- [`http.server`](http.server.xhtml#module-http.server "http.server: HTTP server and request handlers.") 包含基于 [`socketserver`](socketserver.xhtml#module-socketserver "socketserver: A framework for network servers.") 的基本 HTTP 服务类
- [`http.cookies`](http.cookies.xhtml#module-http.cookies "http.cookies: Support for HTTP state management (cookies).") 包含一些有用来实现通过 cookies 进行状态管理的工具
- [`http.cookiejar`](http.cookiejar.xhtml#module-http.cookiejar "http.cookiejar: Classes for automatic handling of HTTP cookies.") 提供了 cookies 的持久化
[`http`](#module-http "http: HTTP status codes and messages") 也是一个通过 [`http.HTTPStatus`](#http.HTTPStatus "http.HTTPStatus") 枚举定义了一些 HTTP 状态码以及相关联消息的模块
*class* `http.``HTTPStatus`3\.5 新版功能.
[`enum.IntEnum`](enum.xhtml#enum.IntEnum "enum.IntEnum") 的子类,它定义了组 HTTP 状态码,原理短语以及用英语书写的长描述文本。
用法:
```
>>> from http import HTTPStatus
>>> HTTPStatus.OK
>>> HTTPStatus.OK == 200
True
>>> http.HTTPStatus.OK.value
200
>>> HTTPStatus.OK.phrase
'OK'
>>> HTTPStatus.OK.description
'Request fulfilled, document follows'
>>> list(HTTPStatus)
[, , ...]
```
## HTTP 状态码
已支持并且已在 [`http.HTTPStatus`](#http.HTTPStatus "http.HTTPStatus") [IANA 注册](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) \[https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml\] 的状态码有:
状态码
映射名
详情
`100`
`CONTINUE`
HTTP/1.1 [**RFC 7231**](https://tools.ietf.org/html/rfc7231.html) \[https://tools.ietf.org/html/rfc7231.html\], Section 6.2.1
`101`
`SWITCHING_PROTOCOLS`
HTTP/1.1 RFC 7231, Section 6.2.2
`102`
`PROCESSING`
WebDAV RFC 2518, Section 10.1
`200`
`OK`
HTTP/1.1 RFC 7231, Section 6.3.1
`201`
`CREATED`
HTTP/1.1 RFC 7231, Section 6.3.2
`202`
`ACCEPTED`
HTTP/1.1 RFC 7231, Section 6.3.3
`203`
`NON_AUTHORITATIVE_INFORMATION`
HTTP/1.1 RFC 7231, Section 6.3.4
`204`
`NO_CONTENT`
HTTP/1.1 RFC 7231, Section 6.3.5
`205`
`RESET_CONTENT`
HTTP/1.1 RFC 7231, Section 6.3.6
`206`
`PARTIAL_CONTENT`
HTTP/1.1 RFC 7233, Section 4.1
`207`
`MULTI_STATUS`
WebDAV RFC 4918, Section 11.1
`208`
`ALREADY_REPORTED`
WebDAV Binding Extensions RFC 5842, Section 7.1 (Experimental)
`226`
`IM_USED`
Delta Encoding in HTTP RFC 3229, Section 10.4.1
`300`
`MULTIPLE_CHOICES`:有多种资源可选择
HTTP/1.1 RFC 7231, Section 6.4.1
`301`
`MOVED_PERMANENTLY`:永久移动
HTTP/1.1 RFC 7231, Section 6.4.2
`302`
`FOUND`:临时移动
HTTP/1.1 RFC 7231, Section 6.4.3
`303`
`SEE_OTHER`:已经移动
HTTP/1.1 RFC 7231, Section 6.4.4
`304`
`NOT_MODIFIED`:没有修改
HTTP/1.1 RFC 7232, Section 4.1
`305`
`USE_PROXY`:使用代理
HTTP/1.1 RFC 7231, Section 6.4.5
`307`
`TEMPORARY_REDIRECT`:临时重定向
HTTP/1.1 [**RFC 7231**](https://tools.ietf.org/html/rfc7231.html) \[https://tools.ietf.org/html/rfc7231.html\], Section 6.4.7
`308`
`PERMANENT_REDIRECT`:永久重定向
Permanent Redirect [**RFC 7238**](https://tools.ietf.org/html/rfc7238.html) \[https://tools.ietf.org/html/rfc7238.html\], Section 3 (Experimental)
`400`
`BAD_REQUEST`:错误请求
HTTP/1.1 RFC 7231, Section 6.5.1
`401`
`UNAUTHORIZED`:未授权
HTTP/1.1 Authentication RFC 7235, Section 3.1
`402`
`PAYMENT_REQUIRED`:保留,将来使用
HTTP/1.1 RFC 7231, Section 6.5.2
`403`
`FORBIDDEN`:禁止
HTTP/1.1 RFC 7231, Section 6.5.3
`404`
`NOT_FOUND`:没有找到
HTTP/1.1 RFC 7231, Section 6.5.4
`405`
`METHOD_NOT_ALLOWED`:该请求方法不允许
HTTP/1.1 RFC 7231, Section 6.5.5
`406`
`NOT_ACCEPTABLE`:不可接受
HTTP/1.1 RFC 7231, Section 6.5.6
`407`
`PROXY_AUTHENTICATION_REQUIRED`:要求使用代理验证身份
HTTP/1.1 Authentication RFC 7235, Section 3.1
`408`
`REQUEST_TIMEOUT`:请求超时
HTTP/1.1 [**RFC 7231**](https://tools.ietf.org/html/rfc7231.html) \[https://tools.ietf.org/html/rfc7231.html\], Section 6.5.7
`409`
`CONFLICT`:冲突
HTTP/1.1 RFC 7231, Section 6.5.8
`410`
`GONE`:已经不在了
HTTP/1.1 RFC 7231, Section 6.5.9
`411`
`LENGTH_REQUIRED`:长度要求
HTTP/1.1 RFC 7231, Section 6.5.10
`412`
`PRECONDITION_FAILED`:前提条件错误
HTTP/1.1 RFC 7232, Section 4.2
`413`
`REQUEST_ENTITY_TOO_LARGE`:请求体太大了
HTTP/1.1 RFC 7231, Section 6.5.11
`414`
`REQUEST_URI_TOO_LONG`:请求URI太长了
HTTP/1.1 RFC 7231, Section 6.5.12
`415`
`UNSUPPORTED_MEDIA_TYPE`:不支持的媒体格式
HTTP/1.1 RFC 7231, Section 6.5.13
`416`
`REQUESTED_RANGE_NOT_SATISFIABLE`
HTTP/1.1 Range Requests RFC 7233, Section 4.4
`417`
`EXPECTATION_FAILED`:期望失败
HTTP/1.1 RFC 7231, Section 6.5.14
`421`
`MISDIRECTED_REQUEST`
HTTP/2 [**RFC 7540**](https://tools.ietf.org/html/rfc7540.html) \[https://tools.ietf.org/html/rfc7540.html\], Section 9.1.2
`422`
`UNPROCESSABLE_ENTITY`:可加工实体
WebDAV RFC 4918, Section 11.2
`423`
`LOCKED`:锁着
WebDAV RFC 4918, Section 11.3
`424`
`FAILED_DEPENDENCY`:失败的依赖
WebDAV RFC 4918, Section 11.4
`426`
`UPGRADE_REQUIRED`:升级需要
HTTP/1.1 RFC 7231, Section 6.5.15
`428`
`PRECONDITION_REQUIRED`:先决条件要求
Additional HTTP Status Codes RFC 6585
`429`
`TOO_MANY_REQUESTS`:太多的请求
Additional HTTP Status Codes RFC 6585
`431`
`REQUEST_HEADER_FIELDS_TOO_LARGE`:请求头太大
Additional HTTP Status Codes RFC 6585
`500`
`INTERNAL_SERVER_ERROR`:内部服务错误
HTTP/1.1 RFC 7231, Section 6.6.1
`501`
`NOT_IMPLEMENTED`:不可执行
HTTP/1.1 RFC 7231, Section 6.6.2
`502`
`BAD_GATEWAY`:无效网关
HTTP/1.1 RFC 7231, Section 6.6.3
`503`
`SERVICE_UNAVAILABLE`:服务不可用
HTTP/1.1 RFC 7231, Section 6.6.4
`504`
`GATEWAY_TIMEOUT`:网关超时
HTTP/1.1 RFC 7231, Section 6.6.5
`505`
`HTTP_VERSION_NOT_SUPPORTED`:HTTP版本不支持
HTTP/1.1 RFC 7231, Section 6.6.6
`506`
`VARIANT_ALSO_NEGOTIATES`:服务器存在内部配置错误
透明内容协商在: HTTP [**RFC 2295**](https://tools.ietf.org/html/rfc2295.html) \[https://tools.ietf.org/html/rfc2295.html\], Section 8.1 (实验性的)
`507`
`INSUFFICIENT_STORAGE`:存储不足
WebDAV RFC 4918, Section 11.5
`508`
`LOOP_DETECTED`:循环检测
WebDAV Binding Extensions RFC 5842, Section 7.2 (Experimental)
`510`
`NOT_EXTENDED`:不扩展
WebDAV Binding Extensions RFC 5842, Section 7.2 (Experimental)
`511`
`NETWORK_AUTHENTICATION_REQUIRED`:要求网络身份验证
Additional HTTP Status Codes [**RFC 6585**](https://tools.ietf.org/html/rfc6585.html) \[https://tools.ietf.org/html/rfc6585.html\], Section 6
为了保持向后兼容性,枚举值也以常量形式出现在 [`http.client`](http.client.xhtml#module-http.client "http.client: HTTP and HTTPS protocol client (requires sockets).") 模块中,。 枚举名等于常量名 (例如 `http.HTTPStatus.OK` 也可以是 `http.client.OK`)。
在 3.7 版更改: 添加了 `421 MISDIRECTED_REQUEST` 状态码。
### 导航
- [索引](../genindex.xhtml "总目录")
- [模块](../py-modindex.xhtml "Python 模块索引") |
- [下一页](http.client.xhtml "http.client --- HTTP协议客户端") |
- [上一页](urllib.robotparser.xhtml "urllib.robotparser --- Parser for robots.txt") |
- ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png)
- [Python](https://www.python.org/) »
- zh\_CN 3.7.3 [文档](../index.xhtml) »
- [Python 标准库](index.xhtml) »
- [互联网协议和支持](internet.xhtml) »
- $('.inline-search').show(0); |
© [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation.
Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/)
最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)?
使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。