apache server can't write to logs - python

Not certain if this belongs here or on SU
I'm developing a Django app and I'm having a problem with logfiles. I have a logger configured to write to /var/log/django/django.log. When I try to start the server, I get a 500 error, and the error log says
ValueError: Unable to configure handler 'djangologfile': [Errno 13] Permission denied: '/var/log/django/django.log'
"httpd/error_log" 480L, 61112C
The permissions for both django.log and the django directory are 777. Why can't the server write to the file?

Well, the easy way to test this is to sudo as a user the server is running under and try to ls /var/log/django/django.log. If that fails you might get insight into what the problem is.

Related

Permission Denied for os.mkdir on ubuntu apache2

I am trying to figure out "To Solve Permission Denied Problem for script.py" python script Hosted on UBUNTU Linux apache2 server. The app is facing problem when I try to use
os.mkdir(os.path.join("/var/www/mysite.com/public_html/uploads", "newfolder"))
Note - app is using mod_wsgi, flask and python 3.x.x version.
This raises an Error 13 Permission denied error. However I tried the same from command line through putty by using
python3
import os
os.mkdir(os.path.join("/var/www/mysite.com/public_html/uploads", "newfolder"))
This created the folder actually. But I don't know why script is failing to create the same in case of execution.
Also Permission is set to "775" for script.py file.

Permission denied when django writes to external device

I have a django file server. The server works perfectly on my laptop & localhost (with external hard drive) but when I transferred it to my Raspberry Pi running Raspbian, it starts acting up.
I did a lot of googling and tried every possible solution but it does not work.
Here is my problem:
I have connected an external hard drive to my raspberry pi. I believe it has write permissions because I can easily write to it with mkdir. I have also set this directory which is /media/pi/SAMSUNG/media as my MEDIA_ROOT.
Now I have set up Apache2, WSGI and Django, everything works, I have set up all the permissions and everything, but still when django tries to access the hard drive, whether it be to read or write, I get an error [Errno 13] Permission denied: '/media/pi/SAMSUNG'.
I have fixed this in the past with chown -R 777 but it does not work this time.
Unfortunetly, I have no idea what I am doing when it comes to servers and file permissions, so I have no idea what code to attach. Can some please help me?
I will attach all the necessary code on request.
Thank you
On raspbian you have to be careful when using external drives. Have you edited the file /etc/fstab? This is necessary to mount the drive also correctly after restarts and when the file is temporarily disconnected and then connected again.
If you did this correctly, then the drive will have the permissions you gave it when mounting and Django should be able to access it/write to it.
BR

Python script can't write file

I have a Flask app hosted on a Linode server. I have a script to fetch a json and write it to a file. When I run this script getprice.py on my server I get the error [Errno 13] Permission denied: 'app/static/prices.json. It works fine on my local machine though. What do I have to do to get it working?
The answer is in your question. The user your script is running as on the server doesn't have write permissions on 'app/static'. It may be helpful if you also posted the getprice.py code, but it seems like a pretty straightforward file permission problem.

Python docker-py Connection Refused

I am having trouble accessing docker daemon from a client using docker-py in Python. I started a docker daemon by the command
sudo docker -d & and the output was [1] 4894. Then I tried to access the daemon from python using the code that I got from here as root
from docker import Client
cli = Client(base_url='unix://var/run/docker.sock')
cli.containers()
This gave me the error:
requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
I also tried
cli = Client(base_url='tcp://127.0.0.1:4894')
but it gave me the same error.
This seems that the /var/run/docker.sock file has the incorrect permissions. As the docker daemon is started as root the permissions are probably to restrictive.
If you change the permissions to allow other users to access it you should have more success (e.g. o=rwx).
The issue is indeed that /var/run/docker.sock has the incorrect permissions.
To fix it, you need to give the current user access to this file.
However, on Linux, giving o=rwx rights to /var/run/docker.sock is very dangerous as it allows any user and service on the system to run commands as root. Indeed access to /var/run/docker.sock implies full root access to the machine. See https://docs.docker.com/engine/security/#docker-daemon-attack-surface
A less dangerous approach consists in creating the group docker and adding the current user to this group. See https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
However, this approach is still potentially dangerous as it gives the current user full root access without the protections that sudo offers (i.e., asking the user password from time to time and logging sudo calls.
See also What is the Docker security risk of /var/run/docker.sock?
(I unfortunately cannot comment hence I write my comment as an answer.)

Download gae application issue, Can't create directory

trying to download the source code from gae developer account.
appcfg.py download_app -A appname /"my folder"/path/appname
When I download the app, it gave me this error:
2013-03-11 14:37:53,807 ERROR appcfg.py:1791 Couldn't create directory "/path-to-folder/admin": [Errno 13] Permission denied: '/path-to-folder'
How to fix this problem?
Edited: Nevermind, I logged in to root and fixed it.
Check if the folder where you try to place the app, has the right permissions set.

Categories