# RuntimeError: No 'Access-Control-Allow-Origin' header is present on the requested resource

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

## Root Cause

Starlette application does not have CORS middleware configured, so cross-origin requests are blocked by the browser.

## Version Compatibility

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

## Workarounds

1. **Add CORSMiddleware from Starlette** (95% success)
   ```
   from starlette.middleware.cors import CORSMiddleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)
   ```
2. **Use FastAPI's built-in CORS middleware if using FastAPI** (90% success)
   ```
   from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(CORSMiddleware, allow_origins=["*"])
   ```

## Dead Ends

- **Adding CORS headers manually in the response** — Doesn't handle preflight OPTIONS requests, causing browser to block the actual request. (75% fail)
- **Disabling CORS check in browser** — Not a production solution; only works for local testing. (90% fail)
