I can’t seem to open and write to a text file from my CGI script.. I keep getting permissions errors (which I see from CGITb)
Whenever I try to do this:
f = open("/Users/varatis/Documents/data.txt","a+")
I get this:
<type 'exceptions.IOError'>: [Errno 13] Permission denied: '/Users/varatis/Documents/data.txt'
args = (13, 'Permission denied')
errno = 13
filename = '/Users/varatis/Documents/data.txt'
message = ''
strerror = 'Permission denied'
Ideally, I’d want to create the text file. But to make things easier for the server, I’ve tried making things easier by making a premade data.txt, and running the usual:
chmod a+x data.txt
chmod a+w data.txt
chown 70 data.txt (70 is the uid the server runs on, obtained by os.getuid from the os module)
however, these don’t even seem to work. Does anyone have experience with this and can help me? Again, ideally I’m appending to the text file from the CGI script and creating it if it doesn’t exist.
Also, maybe of use will be the ls -la for the data.txt:
-rwxrwxrwx@ 1 _www staff 0 Mar 12 16:18 data.txt
Very likely your webserver doesn’t have permissions to write to that specific directory.
If it’s an apache then you might want to fiddle around with ‘Directory’ directive.
update:
What are the permissions on the Documents directory?