Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a .py file in browser

Tags:

python

apache

cgi

I want to run python file in browser. I have installed apache. and configured httd.conf file. I have created test.pyfile. I then tried running test.py with my browser by typing htt://localhost/test.py. When I do this, I get the following error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

In my error log

[Thu Jul 07 18:39:55 2011] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified.  : couldn't create child process: 720002: test.py
[Thu Jul 07 18:39:55 2011] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified.  : couldn't spawn child process: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/test.py

What could be the problem here?

like image 361
Royal Pinto Avatar asked Jul 07 '11 13:07

Royal Pinto


3 Answers

It may also happen if your shebang is not correct (for example, an Unix one like #!/usr/bin/env python). If this is the case, change it to the correct path to your Python executable (for example: #!C:\Python26\python.exe) or look at this answer: How do I ignore the Perl shebang on Windows with Apache 2?

like image 76
minhle_r7 Avatar answered Oct 11 '22 15:10

minhle_r7


Options +ExecCgi under htdocs, ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"

It's what I have and it works

like image 22
Snakes and Coffee Avatar answered Oct 11 '22 16:10

Snakes and Coffee


If it's a CGI program, make sure it conforms to the CGI specification (i.e. it outputs a header line with the MIME type and a blank line before trying to write anything else)

like image 23
deStrangis Avatar answered Oct 11 '22 14:10

deStrangis