The Fix
Upgrade to version 0.13.4 or later.
Based on closed Kludex/uvicorn issue #961 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -3,7 +3,7 @@
import pytest
-from uvicorn.middleware.wsgi import WSGIMiddleware
+from uvicorn.middleware.wsgi import WSGIMiddleware, build_environ
import flask
import uvicorn
app = flask.Flask(__name__)
@app.route("/<keyword>")
def home(keyword):
return keyword
if __name__ == "__main__":
uvicorn.run(app, interface="wsgi")
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.13.4 or later.\nWhen NOT to use: Do not use this fix if your application does not handle non-latin1 paths.\n\n
Why This Fix Works in Production
- Trigger: ERROR: Exception in ASGI application
- Mechanism: The WSGI middleware incorrectly encodes PATH_INFO in utf8 instead of latin1
- Why the fix works: Fixes the WSGI middleware PATH_INFO encoding issue for non-latin1 paths, addressing issue #961. (first fixed release: 0.13.4).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.8.5 in real deployments (not just unit tests).
- The WSGI middleware incorrectly encodes PATH_INFO in utf8 instead of latin1
- Surfaces as: ERROR: Exception in ASGI application
Proof / Evidence
- GitHub issue: #961
- Fix PR: https://github.com/kludex/uvicorn/pull/962
- First fixed release: 0.13.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.37
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Checklist <!-- Please make sure you check all these items before submitting your bug report. --> - [x] The bug is reproducible against the latest release and/or master. - [x] There are no similar issues or pull requests to fix it yet. #”
Failure Signature (Search String)
- ERROR: Exception in ASGI application
Error Message
Stack trace
Error Message
-------------
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 394, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\middleware\wsgi.py", line 64, in __call__
await instance(receive, send)
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\middleware\wsgi.py", line 95, in __call__
await asyncio.wait_for(wsgi, None)
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py", line 455, in wait_for
return await fut
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\uvicorn\middleware\wsgi.py", line 134, in wsgi
for chunk in self.app(environ, start_response):
File "C:\Users\cools\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi
... (truncated) ...
Minimal Reproduction
import flask
import uvicorn
app = flask.Flask(__name__)
@app.route("/<keyword>")
def home(keyword):
return keyword
if __name__ == "__main__":
uvicorn.run(app, interface="wsgi")
Environment
- Python: 3.8.5
What Broke
Sending non-latin1 paths results in a 500 Internal Server Error.
Why It Broke
The WSGI middleware incorrectly encodes PATH_INFO in utf8 instead of latin1
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.4 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/kludex/uvicorn/pull/962
First fixed release: 0.13.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if your application does not handle non-latin1 paths.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.