mod_python: Permission denied

D

David

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.
 
G

Graham Dumpleton

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
 
D

David

A little more info: "Defrosting.rtf" is a file that I wanted to
upload. This file was supposed to upload to folder '/var/www/keyword-
query/files/'.

My code runs in root.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top