Re: small python cgi webserver




Fabian Braennstroem wrote:
Hi,

* ArdPy <ardsrk@xxxxxxxxx> wrote:

Fabian Braennstroem wrote:
Hi,

I am looking for a small python script, which starts a small
web server with python cgi support on a linux machine.

I tried:


#!/usr/bin/env python
import sys
from CGIHTTPServer import CGIHTTPRequestHandler
import BaseHTTPServer

class MyRequestHandler(CGIHTTPRequestHandler):
# In diesem Verzeichnis sollten die CGI-Programme stehen:
cgi_directories=["/home/fab/Desktop/cgi-bin"]


def run():
# 8000=Port-Nummer
# --> http://localhost:8000/
# Fuer http://localhost/
# Port-Nummer auf 80 setzen
httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
httpd.serve_forever()

if __name__=="__main__":
print "Starting Server"
run()

but when I want to test a small python cgi test file:


#!/usr/bin/python
# -*- coding: UTF-8 -*-

# Debugging für CGI-Skripte 'einschalten'
import cgitb; cgitb.enable()

print "Content-Type: text/html;charset=utf-8\n"
print "Hello World!"

I just get the text and not the html output. The file's mode
is 755.

Is there anything wrong with the webserver script or do I do
something completely wrong? Maybe, you have a different
webserver script?

Greetings!
Fabian

Probably the server is not executing your CGI script. If it is the
Apache web server that you are using then just ensure the following
settings in your /etc/httpd/conf/httpd.conf file is exactly like
following:

<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

Maybe, I understood something wrong, but I thought that the
above 'webserver' script would replace apache in my case; at
least I hoped!?

Greetings!
Fabian

Oh yes...Your script is supposed to replace apache. I tried with your
script on my pc and its working just fine. However the problem still is
that the server is taking your file to be a plain file rather than a
CGI script. Looking at CGIHTTPServer.is_cgi method might prove helpful.

.



Relevant Pages

  • Re: Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script ... # have to place corresponding `LoadModule' lines at this location so the ...
    (perl.beginners)
  • Re: Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script Runs perfectly fine from the command prompt. ... # This is the main Apache HTTP server configuration file. ... LoadModule actions_module modules/mod_actions.so ...
    (perl.beginners)
  • Re: How hard is socket programming?
    ... Is socket programming ... Actually, on the server side it is faster than this, because it is just a cgi gateway ... script; the data is sent up uuencoded or some other suitable encoding, ... Apache based web server to copy the received data streams to files ...
    (microsoft.public.vc.mfc)
  • Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script ... # have to place corresponding `LoadModule' lines at this location so the ...
    (perl.beginners)
  • Re: small python cgi webserver
    ... I am looking for a small python script, ... web server with python cgi support on a linux machine. ... Is there anything wrong with the webserver script or do I do ... Apache web server that you are using then just ensure the following ...
    (comp.lang.python)