python
config_error
ai_generated
true
AssertionError: allow_origins must be a list or tuple of strings
ID: python/fastapi-cors-middleware-misconfiguration
80%Fix Rate
87%Confidence
0Evidence
2024-04-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The CORS middleware expects allow_origins as a list, but a string or other type is provided.
generic中文
CORS 中间件期望 allow_origins 为列表,但提供了字符串或其他类型。
Workarounds
-
100% success
Use a list: allow_origins=["*"] or allow_origins=["https://example.com"]
-
95% success
Use allow_origin_regex for pattern matching: allow_origin_regex="https?://.*"
Dead Ends
Common approaches that don't work:
-
100% fail
Starlette's CORSMiddleware requires a list, even for wildcard.
-
90% fail
The assertion checks each element is a string, so non-strings cause failure.