Permission denied on trying to write file

2.6k views Asked by At

I am a python/Django newbie. I am creating folders in my view using:

os.makedirs(path)

The path is different for each file and depends on username and filename combination. On trying to write a file in this folder, I get this error:

IOError at /view_name/
[Errno 13] Permission denied: u'<filepath>'

This is on my windows system. Even on trying to change permission to write from read only, doesn't changes it(its default and only attribute for folders in windows). What should I do?

1

There are 1 answers

0
hajtos On

One possibility is that the directory already exists, which, according to this should raise an error.

It is also possible that the directory is used in some other program, like explorer, and that needs to be closed first.

A third option I can think of is that the default permissions for a directory on your system don't allow reading by a user, in which case your program would need to be run as an administrator or use the win32security module from pywin32 to manually set permissions for the directory(although that may also not work if you don't have permission to change permissions).