python
runtime_error
ai_generated
true
h11._util.LocalProtocolError: 非法的头部值 b'\n'
h11._util.LocalProtocolError: Illegal header value b'\n'
ID: python/uvicorn-h11-local-protocol-error
80%修复率
84%置信度
0证据数
2024-10-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
| 0.110+ | active | — | — | — |
根因分析
响应头包含换行符或非法字符,通常来自用户输入被原样放入 Response(headers=...)。
English
Response header contains a newline or invalid character, often from user input echoed into a header via Response(headers=...).
解决方案
-
92% 成功率
value = value.replace('\r', '').replace('\n', '') # sanitize before setting header -
88% 成功率
Use JSONResponse(body=...) for untrusted data instead of headers.
无效尝试
常见但无效的做法:
-
70% 失败
Embedded \n still present.
-
75% 失败
Same ASGI protocol violation under the hood.