Django permissions hiccup - python

I had all my static and media files working perfectly. However, when I wanted to create a new news article and therefore upload a new picture I got the following error:
[Errno 13] Permission denied:
At the following link I found:
Django [Errno 13] Permission denied: '/var/www/media/animals/user_uploads'
sudo groupadd varwwwusers
sudo adduser www-data varwwwusers
sudo chgrp -R varwwwusers /var/www/
sudo chmod -R 770 /var/www/
Now none of my static files will display on the site at str8red.com
Can anyone help with getting the file permissions back and also allowing the webpage to allow upload of new images.
Many thanks, Alan.

Apologies,
After further digging and grasping the basics of chmod I got there. The links below were very helpful:
www-data permissions?
https://en.wikipedia.org/wiki/Chmod
Many thanks, Alan.

Related

xmlrpc.py permission denied whole running the supervisor

I need to run the laravel jobs in the background and for that reason, I need to run the supervisor on the Linux server.Whenever I try this
supervisorctl reread
It returns this error.
error: <class 'PermissionError'>, [Errno 13] Permission denied: file: /usr/lib/python3/dist-packages/supervisor/xmlrpc.py line: 560
I tried to change the permission of this file
chmod u+X /usr/lib/python3/dist-packages/supervisor/xmlrpc.py
It returns this error
chmod: changing permissions of '/usr/lib/python3/dist-packages/supervisor/xmlrpc.py': Operation not permitted
Any reason why it is not working? I recently upgraded the PHP to 8.1. Is this why it causing the problem?
I used to have the same problem as you, I used sudo at the beginning of the command and it worked fine
sudo supervisorctl reread

pysftp can't create log file - permission denied

I have a small service written in Python 3 which uses pysftp:
with pysftp.Connection(
host=host,
username=connection_data["user"],
port=connection_data["port"], log=log_file, cnopts=cnopts
) as srv:
…
and when I run it (python3 pythonprog.py) I get the following error:
PermissionError: [Errno 13] Permission denied: '/mydisk/folder/logs/pysftp-20181127-231208.log'
Obviously, I don't get this error if I run it with sudo python3 pythonprog.py.
I checked the permissions for this folder:
ls -l
drwxrwxrwx+ 2 myuser myuser 4096 Nov 27 22:38 logs
I also changed ACL with setfacl. Basically, whatever I do the error is still there. How can I grant this permission?
The service is running as someone -- that someone needs permission to write to that file or folder. This is not a code problem, its a permission problem. sudo is not the solution to running the code. I'm taking it that it is running as you? Can you write to that file/folder?

Cannot create file inside Python on Amazon ElasticBeanstalk

I'm trying to create a file inside a Django project on Amazon ElasticBeanstalk WebServer Environment. However it gives me a Permission Denied error.
Here is the error.
Traceback (most recent call last):
File "/opt/python/current/app/foo/boo.py", line 25, in create_file
input_file = open(input_filename, "w")
IOError: [Errno 13] Permission denied: 'testing.txt'
Thanks in advance!
If you want to create file on ElasticBeanstalk, you can, but you shouldn't, you have to use the amazon S3 service for that, with boto3.
But if it's just for a test you can add permisson with the .ebextensions file :
.ebextensions/instance.config
container_commands:
# Permisson on deploy command
0.0.0.files.chmod.ondeck:
command: "chmod u+xwr -R /opt/python/ondeck/app"
# Permisson on run dir
0.0.1.files.chmod.run:
command: "chmod u+xwr -R /opt/python/current/app"
I suggest you to create a folder in your app just for that. Than you can XX_permissions.config in your .ebextensions folder.
container_commands:
01_change_my_folder_permissions:
command: "mkdir -p /opt/python/current/app/my_folder; chmod 777 -R /opt/python/current/app/my_folder"
The command create the folder if doesn't exists and set the permissions. Just verify that your instance got the right permissions connecting directly using the ssh. Run the eb ssh [name-of-your-env] and check if the permission are ok:
ls -l /opt/python/current/app/
You should see your folder with a permission like drwxrwxrwx in the list.

Chmod in Python - [Errno 1] Operation not permitted

I'm trying to modify an application in my /Applications folder on OS X. I need to get read and write permissions, so I currently have:
os.chmod(appDir, 0644)
where appDir is the directory of my app. However, whenever I run the program, I get the error:
OSError: [Errno 1] Operation not permitted: '/Applications/Simplenote.app'
I would try sudo, but how would you enter the password through Python? (this is a Python script by the way)
Any help is appreciated.
If you are trying to run the script from a web site, change the target folders/files to be owned by the web user, e.g. www-data. sudo chown www-data * -R That fixed it for me.

Error during git pull in python fabric

I am using python fabric in my project mainly for deployment to the remote server. Inside the fabfile, i have written a function named deploy() for pulling the code to the github. When i execute the command "fab deploy", it results in an error like this:
error: cannot open .git/FETCH_HEAD: Permission denied
Please help me in resolving this issue. Any help is much appreciated. Thanks in advance
Check permissions and ownership of .git directory and files in it
ls -al .git | grep FETCH_HEAD
There should be something like -rw-r--r-- at the beginning of output.
If not fix it by setting them by:
sudo chmod -R 0755 .git

Categories

Resources