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. But I have given persmission to all users, groups, andd others to my python file:
sudo chmod a=rwx python_file.py
And still the python file is not executed. Using subprocess.Popen
instead of subprocess.call
does not work, and neither does setting shell = True
.
Anyone has any idea of what I am missing here? Otherwise I'll try to switch over to CGI and drop subprocessing for running scripts :-)
subprocess.check_output
to see what's going on. the script is probably called, setting execution rights doesn't help since it's an argument ofpython
, it's just that it fails silently – Jean-François Fabre♦ Nov 1 '17 at 6:52Popen
andcommunicate
to get the standard error output of the command. – Jean-François Fabre♦ Nov 1 '17 at 7:22