# TypeError: can't compare offset-naive and offset-aware datetimes

- **ID:** `python/fastapi-datetime-timezone-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

在比较或计算中混合使用了带时区和不带时区的 datetime 对象。

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   统一使用 `datetime.now(timezone.utc)` 确保所有 datetime 对象带时区。
   ```
2. **** (85% success)
   ```
   在比较前使用 `astimezone(timezone.utc)` 转换。
   ```

## Dead Ends

- **** — 尝试使用 `datetime.utcnow()` 但未设置时区，导致与带时区的时间比较失败。 (70% fail)
- **** — 尝试在 Pydantic 模型中使用 `datetime` 但未指定时区，导致序列化时出错。 (60% fail)
