mod_python: Permission denied

Graham Dumpleton graham.dumpleton at gmail.com
Wed Aug 26 00:48:38 CEST 2009


On Aug 26, 8:43 am, David <ww... at yahoo.com> wrote:
> Hello,
>
> I googled online however I did not find a clue my question. So I post
> it here.
>
> I created a mod_python CGI to upload a file and saves it in folder "/
> var/www/keyword-query/files/".  My code runs in root.
>
>      fileitem = req.form['file']
>
>    # Test if the file was uploaded
>    if fileitem.filename:
>
>       # strip leading path from file name to avoid directory traversal
> attacks
>       fname = os.path.basename(fileitem.filename)
>       # build absolute path to files directory
>       dir_path = os.path.join(os.path.dirname(req.filename), 'files')
>       f = open(os.path.join(dir_path, fname), 'wb', 10000)
>
>       # Read the file in chunks
>       for chunk in fbuffer(fileitem.file):
>          f.write(chunk)
>       f.close()
>       message = 'The file "%s" was uploaded successfully' % fname
>
> I got:
>
>  File "/var/www/keyword-query/upload.py", line 30, in upload
>     f = open(os.path.join(dir_path, fname), 'wb', 10000)
>
> IOError: [Errno 13] Permission denied: '/var/www/keyword-query/files/
> Defrosting.rtf'
>
> "Defrosting.rtf" is a file on the desktop of my Windows XP computer.
>
> Anybody knows what the problem is?
>
> Thanks for your replies.

Apache service likely running as a special user which doesn't have
write permission to your directory.

Graham



More information about the Python-list mailing list