`TypeError: 'NoneType' object is not subscriptable` in `pod.status.container_statuses[0]`.
BeginnerTroubleshootingRuntime, file, subprocess & encoding errors
Answer
Likely causes → Kubernetes client fields are None until populated: pending pods have no container_statuses; last_state.terminated is None if the container never terminated.
Diagnose →
print(pod.status.phase, pod.status.container_statuses)
Fix → Guard: for cs in pod.status.container_statuses or []: and check cs.last_state.terminated is not None.
Prevent → Treat every nested API field as optional; use type hints so mypy flags Optional access.
More on Runtime, file, subprocess & encoding errors
`KeyError: 'Tags'` while processing `describe_instances` output.Beginner`TypeError: can't compare offset-naive and offset-aware datetimes` in a snapshot-age check.Beginner`UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte` reading a log file.Intermediate`UnicodeEncodeError: 'ascii' codec can't encode character '✓'` when printing in a container.Intermediate`PermissionError: [Errno 13] Permission denied: '/var/log/app/report.json'`Intermediate`OSError: [Errno 24] Too many open files` in a long-running Python service.Intermediate