python
runtime_error
ai_generated
true
h11._util.LocalProtocolError: Illegal header value b'\n'
ID: python/uvicorn-h11-local-protocol-error
80%Fix Rate
84%Confidence
0Evidence
2024-10-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
| 0.110+ | active | — | — | — |
Root Cause
Response header contains a newline or invalid character, often from user input echoed into a header via Response(headers=...).
generic中文
响应头包含换行符或非法字符,通常来自用户输入被原样放入 Response(headers=...)。
Workarounds
-
92% success
value = value.replace('\r', '').replace('\n', '') # sanitize before setting header -
88% success
Use JSONResponse(body=...) for untrusted data instead of headers.
Dead Ends
Common approaches that don't work:
-
70% fail
Embedded \n still present.
-
75% fail
Same ASGI protocol violation under the hood.