python type_error ai_generated true

值错误:99 不是有效的 HTTP 状态码

ValueError: 99 is not a valid HTTP status code

ID: python/starlette-http-exception-invalid-status

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-11-05首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

向 HTTPException 或 Response 传递了无效的状态码。

English

Passing an invalid status code to HTTPException or Response.

generic

解决方案

  1. 100% 成功率
    Use a valid status code: raise HTTPException(status_code=404, detail='Not Found')
  2. 90% 成功率
    Check the status code before using: if 100 <= code <= 599: use it else: raise ValueError

无效尝试

常见但无效的做法:

  1. 90% 失败

    Status codes must be integers between 100 and 599.

  2. 80% 失败

    600 is not a standard HTTP status code.