Python Falcon 简明教程

Python Falcon - Status Codes

默认情况下,HTTP 服务器对客户端请求的响应具有 200 OK 状态。Falcon 提供了自己的状态常量列表,以提高便利性和可读性。

例如,200 OK 状态代码表示为:

resp.status = falcon.HTTP_OK

这些预定义的 Falcon 常量避免了输入错误,并减少了准备响应时必须创建的字符串对象数量。然而,从 Falcon 3.0 版本开始,允许使用 int 代码。

resp.status = 200

对于 ASGI 应用程序,相同的状态代码适用。

Falcon 库中定义的部分状态代码如下:

Informational Codes

  1. HTTP_CONTINUE = HTTP_100

  2. HTTP_SWITCHING_PROTOCOLS = HTTP_101

  3. HTTP_PROCESSING = HTTP_102

Success Status Codes

  1. HTTP_OK = HTTP_200

  2. HTTP_CREATED = HTTP_201

  3. HTTP_ACCEPTED = HTTP_202

  4. HTTP_NON_AUTHORITATIVE_INFORMATION = HTTP_203

  5. HTTP_NO_CONTENT = HTTP_204

  6. HTTP_RESET_CONTENT = HTTP_205

  7. HTTP_PARTIAL_CONTENT = HTTP_206

  8. HTTP_MULTI_STATUS = HTTP_207

  9. HTTP_ALREADY_REPORTED = HTTP_208

  10. HTTP_IM_USED = HTTP_226

Redirection Error Codes

  1. HTTP_MULTIPLE_CHOICES = HTTP_300

  2. HTTP_MOVED_PERMANENTLY = HTTP_301

  3. HTTP_FOUND = HTTP_302

  4. HTTP_SEE_OTHER = HTTP_303

  5. HTTP_NOT_MODIFIED = HTTP_304

  6. HTTP_USE_PROXY = HTTP_305

  7. HTTP_TEMPORARY_REDIRECT = HTTP_307

  8. HTTP_PERMANENT_REDIRECT = HTTP_308

Client Error Codes

  1. HTTP_BAD_REQUEST = HTTP_400

  2. HTTP_UNAUTHORIZED = HTTP_401 # "未验证"

  3. HTTP_PAYMENT_REQUIRED = HTTP_402

  4. HTTP_FORBIDDEN = HTTP_403 # "未授权"

  5. HTTP_NOT_FOUND = HTTP_404

  6. HTTP_METHOD_NOT_ALLOWED = HTTP_405

  7. HTTP_NOT_ACCEPTABLE = HTTP_406

  8. HTTP_PROXY_AUTHENTICATION_REQUIRED = HTTP_407

  9. HTTP_REQUEST_TIMEOUT = HTTP_408

  10. HTTP_CONFLICT = HTTP_409

Server Error Codes

  1. HTTP_INTERNAL_SERVER_ERROR = HTTP_500

  2. HTTP_NOT_IMPLEMENTED = HTTP_501

  3. HTTP_BAD_GATEWAY = HTTP_502

  4. HTTP_SERVICE_UNAVAILABLE = HTTP_503

  5. HTTP_GATEWAY_TIMEOUT = HTTP_504

  6. HTTP_HTTP_VERSION_NOT_SUPPORTED = HTTP_505

  7. HTTP_INSUFFICIENT_STORAGE = HTTP_507

  8. HTTP_LOOP_DETECTED = HTTP_508

  9. HTTP_NETWORK_AUTHENTICATION_REQUIRED = HTTP_511