# AssertionError: allow_origins 必须是字符串的列表或元组

- **ID:** `python/fastapi-cors-middleware-misconfiguration`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

CORS 中间件期望 allow_origins 为列表，但提供了字符串或其他类型。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (100% 成功率)
   ```
   Use a list: allow_origins=["*"] or allow_origins=["https://example.com"]
   ```
2. **** (95% 成功率)
   ```
   Use allow_origin_regex for pattern matching: allow_origin_regex="https?://.*"
   ```

## 无效尝试

- **** — Starlette's CORSMiddleware requires a list, even for wildcard. (100% 失败率)
- **** — The assertion checks each element is a string, so non-strings cause failure. (90% 失败率)
