python
network_error
ai_generated
true
HTTP/1.1 400 Bad Request CORS preflight request failed: missing Access-Control-Request-Method
ID: python/fastapi-cors-preflight-400
80%Fix Rate
87%Confidence
0Evidence
2025-09-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
Root Cause
CORSMiddleware not added, or added after other middleware that short-circuits OPTIONS; or allow_methods excludes the method.
generic中文
未添加 CORSMiddleware,或在会短路 OPTIONS 的中间件之后添加;或 allow_methods 未包含该方法。
Workarounds
-
95% success
app.add_middleware(CORSMiddleware, allow_origins=['https://app.example.com'], allow_methods=['GET','POST','PUT','DELETE','OPTIONS'], allow_headers=['*'], allow_credentials=True) — add FIRST before other middlewares.
-
90% success
Verify order: middleware added later wraps earlier ones; CORS should be outermost.
Dead Ends
Common approaches that don't work:
-
80% fail
Tedious and misses middleware ordering; CORSMiddleware already handles preflight.
-
90% fail
Browsers reject wildcard with credentials.