1

I have a simple form that submits a select box. When the submit button is pressed I run a python script that needs to create a new directory and add files from an repository. Currently I cannot get the python script to have the ability to create a directory.

Adding :

import cgitb
cgitb.enable()

to my script gave me a

<type 'exceptions.OSError'>: [Errno 13] Permission denied: '../prPages/myNewFolderTest'

error.

What do I need to be looking for/at as far as file permissions on the script, on the folders I am creating my sub folders in? What does one look at when having a python script manipulate files from a server environment?

1

I agree with Stephen Ostermiller's answer but I'd like to add an easy way to fix your issue. I'm assuming you're using linux.

I bet there is a function you can call in python to get the current username of the running script. You need to know this (or at least the group the user is in), otherwise you'll be playing a guessing game with the server.

Another way to get the username is to ask the server admin to login to shell as root and change to the same folder you want a file to be created in (I'll call it folder x from here on in), then the server admin can execute:

ls -al

then look at the top entry to find something like this:

drwxr-xr-x 21 incoming 500 4096 2015-02-05 15:15 ./

Make sure the right-most item is a './' so you know the info of folder x.

Now the easiest way out (but not the most secure) is to change permissions to 777 so that everyone has read and write access to the folder.

When the permissions are changed and you retrieve the listing again, you should see this:

drwxrwxrwx 21 incoming 500 4096 2015-02-05 15:15 ./

You may also need to define a default umask (which is equal to 777 minus permissions) to define the default permissions if none are explicitly set for each file or folder you create.

  • No! 777 will let the entire world edit this folder to, say, upload a malicious python script of their own, or an ad page that destroys your SEO. – Daniel F Mar 21 '15 at 5:54
  • I did mention Now the easiest way out (but NOT the most secure) is to change permissions to 777 so that everyone has read and write access to the folder.. I was just merely offering a way to solve a permission denied issue. – Mike Mar 21 '15 at 22:18
  • Sorry. It sounded like you said that this is an acceptable security risk, which it isn't. – Daniel F Mar 22 '15 at 2:52
0

Your directory needs to be writable by the user that is running the webserver. That is going to be different on different operating systems, even different between different Linux distributions.

On my Ubuntu server, the webserver is run by the user www-data. To fix the permissions, I would use this command:

sudo chown -R www-data /var/www/example.com/prPages/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.