How to execute python script on the BaseHTTPSERVER created by python?

Posted by user1731699 on Stack Overflow See other posts from Stack Overflow or by user1731699
Published on 2012-10-25T09:14:19Z Indexed on 2012/10/25 11:01 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

I have simply created a python server with :

python -m SimpleHTTPServer

I had a .htaccess (I don't know if it is usefull with python server) with:

AddHandler cgi-script .py
Options +ExecCGI

Now I am writing a simple python script :

#!/usr/bin/python
import cgitb
cgitb.enable()
print 'Content-type: text/html'
print '''
<html>
     <head>
          <title>My website</title>
     </head>
     <body>
          <p>Here I am</p>
     </body>
</html>
'''

I make test.py (name of my script) an executed file with:

chmod +x test.py

I am launching in firefox with this addres: (http : //) 0.0.0.0:8000/test.py

Problem, the script is not executed... I see the code in the web page... And server error is:

localhost - - [25/Oct/2012 10:47:12] "GET / HTTP/1.1" 200 -
localhost - - [25/Oct/2012 10:47:13] code 404, message File not found
localhost - - [25/Oct/2012 10:47:13] "GET /favicon.ico HTTP/1.1" 404 -

How can I manage the execution of python code simply? Is it possible to write in a python server to execute the python script like with something like that:

import BaseHTTPServer
import CGIHTTPServer
httpd = BaseHTTPServer.HTTPServer(\
    ('localhost', 8123), \
CGIHTTPServer.CGIHTTPRequestHandler)
###  here some code to say, hey please execute python script on the webserver... ;-)
httpd.serve_forever()

Or something else...

© Stack Overflow or respective owner

Related posts about python

Related posts about http