# TypeError: 'CORSMiddleware' object is not callable

- **ID:** `python/fastapi-cors-middleware-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI中CORSMiddleware未正确添加到应用，导致被当作可调用对象处理。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **使用add_middleware正确添加CORS中间件** (95% success)
   ```
   from fastapi.middleware.cors import CORSMiddleware; app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=['*'], allow_headers=['*'])
   ```
2. **使用Starlette的CORSMiddleware并手动添加** (90% success)
   ```
   from starlette.middleware.cors import CORSMiddleware; app.add_middleware(CORSMiddleware, allow_origins=['*'])
   ```

## Dead Ends

- **直接导入CORSMiddleware并作为装饰器使用** — CORSMiddleware是类，需要实例化。 (90% fail)
- **在路由中使用CORSMiddleware作为依赖项** — 依赖项需要可调用对象。 (80% fail)
