I am running a python CGI script which must create a video at a directory location.
Platform : Ubuntu 14.04 64-bit
Python Version : 2.7.6
The script is being run by the user : www-data
I have a directory mydir
.
The permissions to mydir
are 777
(recursive). This directory is owned by user: www-data
and group www-data
.
The Python script creates a new directory in a sub-directory of mydir
, but there is an Exception raised:
IOError: [Errno 13] Permission denied: 'path/to/file.ext'
I observed that the new directory which was created, surprisingly had the following state:
drwxrwxr-x 3 me me 4096 <Timestamp> newdir
When I checked earlier the process was being run by www-data
but now the folder is owned by the current user I am logged into. (indicated by 'me'
here).
Moreover all permissions are set except check the others permissions r-x
. NO WRITE PERMISSIONS. That justifies the exception raised.
I tried to do a os.umask(0000)
as well as os.chmod('mydir',0777)
. First one did not have any effect. Second one, I don't have permissions somehow. Can somebody please help. This issue is real irritating. What am I missing here?
Note: The python file is triggered as follows: A cronjob
calls a PHP
file which after some processing then sends a post request to the Python
script.
EDIT: Please let me know if the solution by @MattDMo works (I won't be testing it as I have changed my approach). I will mark it as accepted if somebody finds it working.