错误响应

对于所有的请求,响应格式都是一个 JSON 对象,结构如下:

字段名 类型 说明
status string 恒为 error
error_msg string 错误描述

示例代码

  1. import requests
  2. # 请求参数
  3. playload = {
  4. "email": "hgzchn@qq.com",
  5. "password": "itellyou"
  6. }
  7. # 请求头
  8. headers = {
  9. "Content-Type": "application/json",
  10. "X-Hydrogen-Client-ID": "0f17262d58e0071e6cf3"
  11. }
  12. # 假设此应用未开始邮箱注册,则会发生错误
  13. response = requests.post(
  14. url="http://{{服务器域名}}/hserve/v2.0/register/email/",
  15. headers=headers,
  16. data=playload
  17. )
  18. print(response.status_code)
  19. # 405
  20. print(response.json())
  21. # {'status': 'error', 'error_msg': 'Please enable email login first.'}

错误码详解

响应的 HTTP 状态码列表(status_code)与其含义

400 Bad Request 参数错误

401 Unauthorized 未授权

402 Payment Required 应用欠费

403 Forbidden 禁止访问

404 Not Found 服务器找不到给定的资源

405 Method Not Allowed 不允许的请求方法

500 Internal Server Error 内部服务器错误