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

`PermissionError: [Errno 13] Permission denied: '/var/log/app/report.json'`

IntermediateTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → The process user cannot write there: wrong owner, non-root container user writing to a root-owned mount, read-only filesystem, or SELinux labels.

Diagnose →

id; ls -ld /var/log/app; ls -l /var/log/app/report.json
mount | grep " /var/log "
ls -Z /var/log/app        # SELinux

Fix → Write to a directory the user owns (/tmp, a volume with correct fsGroup/ownership), fix ownership, or for bind mounts add :Z on SELinux hosts.

Prevent → Make output paths configurable; set Kubernetes securityContext.fsGroup for volumes.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors