0

I am working on a home automation project, and I want to run certain python codes when going to certain URLs of my Django Webpage. The subprocess.call() line from my Django Views.py works perfectly on my Django development server:

from django.http import HttpResponse
import subprocess

def home():
    subprocess.call(['python','path_to_python_file/python_file.py'])
    html = "<html><h1>Hello World</h1></html>" 
    return HttpResponse(html)

But the python script (or whatsoever command line) is not called on my Raspberry with Apache. According to many previous questions I've read, this could either be a SELinux issue or an premission issue (the Django/Apache user and group does not have permission to run commands).

Anyone can give me a hand on how to check whether this is caused by one or the other, and how to either configure SELinux or giving permission to Django/Apache to run commands?

  • 1
    You might try printing the value of subprocess.call(...). It should return an error code; if 0, it ran fine (in theory), otherwise, an error occurred. – Aurora0001 Oct 31 '17 at 20:27
  • Another possibility is that python is not on the path for the shell used by your Django/Apache process. Instead of python in the subprocess.call you might try specifying the full path to python on your machine. – Brick Nov 1 '17 at 13:42

Your Answer

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

Browse other questions tagged or ask your own question.