Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

`TypeError: can't compare offset-naive and offset-aware datetimes` in a snapshot-age check.

BeginnerTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → boto3 returns timezone-aware datetimes (StartTime) and the code compares with naive datetime.now() or datetime.utcnow().

Diagnose →

print(snap["StartTime"].tzinfo, datetime.now().tzinfo)

Fix → from datetime import UTC, datetime; cutoff = datetime.now(UTC) - timedelta(days=90).

Prevent → Always use aware UTC datetimes; ruff rule DTZ005 flags naive now().

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors