Python Forum
PermissionError: [Errno 13] Permission denied:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PermissionError: [Errno 13] Permission denied:
#1
Hello,

I am trying to write basic data to a csv file and I keep getting a (PermissionError: [Errno 13] Permission denied: 'test_csv.csv') error. I have tried moving my csv file (test_csv.csv) to different locations on my C drive but I still get the same error. Can you see any problems with my below code that would cause this error?

import os
import csv

def write_to_csv_file():
	
	path = r"C:\Documents\test_csv.csv"
	
	print(os.getcwd())
	
	with open("test_csv.csv", "w") as file:
		new_content = "New content to replace the existing content."
		file.write(new_content)

		print("File content modified successfully!")
Thanks,
Tuurbo46
Reply
#2
The question has nothing to do with csv. It has nothing to do with python. This is a file permissions error. Do you have permission to create the file you are trying to create? If the file already exists, do you have permission to modify the file?

Use icacls in the CMD shell or get-acl from the powershell to list permissions for a file.

I have a question about your program. What is the purpose of path? It is not used. Your program tries to create "test_csv.csv" in the current working directory, not in c:\Documents. The current working directory is usually the directory where your python program resides, unless you specify a path when running your python file.
Reply
#3
Hello deanhystad,

Your feedback was correct.

The permission on the project folder was read-only. When I updated to write, I was then able to create a new test_csv file in the Python project directory.

Thanks,
Tuurbo46
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020