# RuntimeError: Working outside of request context.

- **ID:** `python/flask-request-context-missing`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

在请求上下文之外（如后台线程或定时任务）访问了 request 对象。

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   with app.test_request_context('/'):
    # 访问 request
   ```
2. **** (85% success)
   ```
   def background_task(request_data):
    # 使用传递的数据
   ```

## Dead Ends

- **** — 需要模拟请求，但无法获取真实请求数据。 (60% fail)
- **** — 全局变量在并发环境下不安全。 (70% fail)
