Mobile app version of vmapp.org
Login or Join
Gloria169

: How to setup server, file permissions, and python script so that python script can create files and directories I have a simple form that submits a select box. When the submit button is pressed

@Gloria169

Posted in: #Files #Python

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Gloria169

2 Comments

Sorted by latest first Latest Oldest Best

 

@Annie201

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.

10% popularity Vote Up Vote Down


 

@Megan663

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/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme