Running .py file in browser

I want to run a python file in a browser. I installed apache. and the configured httd.conf file. I created a test.py file. Then I tried to run test.py using 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, lohith.pinto@primefocusworld.com 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?

+6
source share
7 answers

This can happen if your shebang is incorrect (e.g. Unix, e.g. #!/usr/bin/env python ). If so, change it to the correct path to the Python executable (for example: #!C:\Python26\python.exe ) or look at this answer: How to ignore Perl-shebang on Windows with Apache 2?

+10
source

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

This is what I have and it works

+2
source

If it is a CGI program, make sure that it complies with the CGI specification (i.e. prints a header line with a MIME type and an empty string before trying to write anything else)

+1
source

If you have not already done so, you need to set the correct permissions on test.py to 755.

0
source

Is the file in C: / Program Files (x86) / Apache Software Foundation / Apache2.2 / htdocs / as indicated in the error message. If not, you need to put it there or change the configuration so that it looks in the right place.

Also, as other answers, check that it has the correct permissions and check that it displays all the necessary headers.

0
source

I would change your URL to a more likely one in the first instance, i.e. http://localhost/test.py , not the one you specified ( htt://localhost/test.py )

0
source

you can try mod_python, it supports web applications written in python.The parser is built into the server as an apache module, so the application runs faster than traditional cgi. Also, if you want to adhere to the cgi method, make sure that all .py files are in a folder named "cgi-bin" and have execute rights.

0
source

Source: https://habr.com/ru/post/892237/


All Articles