# 断言错误：'allow_origins' 必须是字符串列表或单个字符串

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

## 根因

向 CORSMiddleware 的 allow_origins 传递了无效类型，如集合或元组。

## 版本兼容性

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

## 解决方案

1. **** (100% 成功率)
   ```
   Use a list: allow_origins=['*'] or allow_origins=['http://example.com']
   ```
2. **** (80% 成功率)
   ```
   If you need dynamic origins, use a function that returns a list
   ```

## 无效尝试

- **** — FastAPI expects a list; set is not accepted. (90% 失败率)
- **** — It's allowed but may cause issues with credentials; the assertion is for non-string types. (30% 失败率)
