0

So, I have a Python Server Pages script that when ran, saves stuff to a file in /var/www/. It opens the file with:

open(filename, 'wb')

Which causes this:

IOError: [Errno 13] Permission denied: 'file.txt'

I'm using Apache and have set /var/www/ to chmod 755. I'm not sure if www-data is trying to write, since when I run this, the output is simply 0:

<%
import os
req.write(str(os.system('whoami')))
%>

I chown'd it to www-data anyway, but it still doesn't work. Can anyone give me any pointers?

user1814016
  • 2,273
  • 5
  • 25
  • 28
  • Why do you use mod_python? It's obsolete since a long time in favour of mod_wsgi. Mixing code and HTML (PSP/PHP-style) is also a pretty bad idea. Consider switching to a small-footprint WSGI framework such as [Flask](http://flask.pocoo.org) – ThiefMaster Nov 16 '12 at 12:18

1 Answers1

0

Didn't do enough searching, managed to solve it by writing using the full path, ie.

open('/var/www/' + filename, 'wb')

instead of

open(filename, 'wb')
user1814016
  • 2,273
  • 5
  • 25
  • 28