On my Pi3 running Raspian, Apache server I have a Django App.
I'm trying to run a python file from Django.
If I SSH into my Pi and type "python test_data.py", it runs fine. I SSH in as user "pi"
test_data.py is just this.
output = "success!"
print(output)
urls.py
url(r'^mygame/$', views.my_game),
views.py file I have the following
from subprocess import PIPE, run
def my_game(request):
command = ['sudo', 'python test_data.py']
result = run(command, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True)
return render(request, 'rungame.html',{'data1':result})
When /mygame is called via the web browser, here is the result I get printed in rungame.html, so I know it calls test_data.py. It appears to be a permissions issue? I don't understand what the following means. Can someone advise if this is a permissions issue and how do I fix it?
CompletedProcess(args=['sudo', 'python mygame.py'], returncode=1, stdout='', stderr='usage: sudo -h | -K | -k | -V\
nusage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]\
nusage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]\n [command]\
nusage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p\n prompt] [-u user] [VAR=value] [-i|-s] [<command>]\
nusage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p\n prompt] [-u user] file ...\n')
Thank you
ADDED INFO: mygame.py created to test the concept
import pygame
import sys
pygame.init()
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
background = pygame.image.load('background1.png')
print("test")
game_over = False
while not game_over:
screen.blit(background, (0, 0))
pygame.display.update()
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
sys.exit()
HERE IS MY APACHE CONF FILE
<VirtualHost *:80>
ServerName www.example.com
ServerAdmin webmaster@localhost
Alias /static /home/pi/Dev/ehome/src/static
<Directory /home/pi/Dev/ehome/src/static>
Require all granted
</Directory>
<Directory /home/pi/Dev/ehome/src/ehome>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess ehome python-path=/home/pi/Dev/ehome/src:/home/pi/Dev/ehome/lib/python3.5/site-packages
WSGIProcessGroup ehome
WSGIScriptAlias / /home/pi/Dev/ehome/src/ehome/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
pieneeds to have permission to execute the python script. You are trying to execute thedjangoapplication throughapacheright?apache's user (www:data) as thegroup ownerand give it permission to execute thewsgi.pyinside your application. I think you need to use something likemodwsgias well. For more info you may look at docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi