Page 1 of 1

Urgent help needed! Where to put my Python CGI

Posted: Fri Feb 28, 2014 3:36 am
by yvonnezoe
I have Apache2 web server running on my raspberry Pi and i have this camera app ( ... 43&t=63276) installed too. but i'm not sure what web server is the app running. :(

I could host a simple web interface on localhost and i wanted to run a python file from my web interface so that I can control a servo by clicking the button.

I tried to use php exec function or jquery post method but all failed. so now i want to try CGI (a totally new term to me). According to this tutorial ... amming.htm, I am suppose to find cgi-bin under /var/www but I found it in /usr/lib instead.

I tried to write a simple cgi as such ... ry-pi.html and put it in /usr/lib/cgi-bin. But when i go to this link localhost/cgi-bin/hello.cgi, there is nothing shown. So I wonder where should I put my cgi file? I wanted to write a python cgi instead of a bash cgi.

Or is there any alternative to call and run the python function from the webpage? I tried CherryPy before but the webpage itself is in the python script so i can just link the function... but I have no idea how to insert the camera app into my app that will be ran by cherrypy.

UPDATE: I have just successfully display a "hello world" at http://localhost/cgi-bin/ However, now my question is, can i just run the python file without displaying anything?? As in without redirecting to a new page?

Re: Urgent help needed! Where to put my Python CGI

Posted: Fri Feb 28, 2014 5:53 pm
by DougieLawson
Your python program needs to send http headers even if there is no output.

You could send a response code 204 (instead of 200).

Code: Select all

print "'HTTP/1.0 204 NO CONTENT\r\n\r\n"