1

I am trying to execute python script in apache2 server but apache2 server downloads python file instead of executing it. I am sending request to server using xmlhttprequest object in javascript I have given url as filename(test.py) in xmlhttprequest object. Added handler for cgi and mod_python in apache config file but it did not work

#!/usr/bin/python
import cgi
import cgitb
cgitb.enable()
from mod_python import apache
print "hello world"

html code

<!DOCTYPE html>
<html>
<head>
<script>
    function runJS() {
      var code = Blockly.C.workspaceToCode(Code.workspace);
      var xmlhttp=new XMLHttpRequest();
      xmlhttp.open("POST","/cgi-bin/process.py",false);
      xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      xmlhttp.send("code=" + encodeURIComponent(code));
      alert(xmlhttp.responseText);
     }
</script>
</head>
<body>
    <button onclick="runJS()">click</button>
</body>
</html>

My apache config file for mod_python

<Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    AddHandler mod_python .py
    PythonHandler mod_python.publisher | .py
    PythonDebug On
</Directory>

for cgi

ScriptAlias "/cgi-bin/" "/var/www/html/cgi-bin/"
<Directory /var/www/html/cgi-bin>
    Options ExecCGI Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    AddHandler cgi-script .py
</Directory>

or suggest any alternate way to execute python script in webserver

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.