small python cgi webserver

Fabian Braennstroem f.braennstroem at
Sat Nov 4 09:47:48 CET 2006


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:
  def run():
      # 8000=Port-Nummer
      #   --> http://localhost:8000/
      # Fuer http://localhost/ 
      #   Port-Nummer auf 80 setzen
      httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
  if __name__=="__main__":
      print "Starting Server"

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

  # -*- 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?


More information about the Python-list mailing list