# RuntimeError: The session is not available for the current request.

- **ID:** `python/flask-runtimeerror-session-not-available`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Session is accessed outside of a request context or before it's initialized.

## Version Compatibility

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

## Workarounds

1. **Ensure request context is active** (90% success)
   ```
   with app.test_request_context():
    session['key'] = 'value'
    print(session['key'])
   ```
2. **Initialize session in route** (95% success)
   ```
   @app.route('/login')
def login():
    session['user'] = 'Alice'
    return 'Logged in'
   ```

## Dead Ends

- **Setting secret_key after session access** — Secret key must be set before first session use. (75% fail)
- **Using flask.session without import** — Session object not available without import. (60% fail)
