# KeyError: 'session_id'

- **ID:** `python/starlette-request-cookie-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Starlette 请求中访问不存在的 Cookie。

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   使用 request.cookies.get('session_id') 并检查 None
   ```
2. **** (90% success)
   ```
   使用 SessionMiddleware 处理会话
   ```
3. **** (85% success)
   ```
   设置默认值
   ```

## Dead Ends

- **** — 如果 Cookie 不存在，会抛出 KeyError。 (80% fail)
- **** — 导致 500 错误。 (70% fail)
- **** — 可能返回空字符串，但业务逻辑可能不接受。 (60% fail)
