# TypeError: Object of type datetime is not JSON serializable

- **ID:** `python/flask-session-serialization-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Storing non-JSON-serializable values (datetime, Decimal, custom classes) in the Flask session cookie.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   session['ts'] = dt.isoformat()\n# read back: datetime.fromisoformat(session['ts'])
   ```
2. **** (90% success)
   ```
   app.config['SESSION_TYPE'] = 'redis'\nSession(app)
   ```

## Dead Ends

- **** — Unrelated to serialization. (95% fail)
- **** — Only affects expiry, not encoding. (90% fail)
