HTTP server

placid Bulkan at
Sun Jun 25 15:16:09 CEST 2006

Simon Forman wrote:
> Ok, seriously,  I don't know how pydoc does it, but when I need a
> quick-and-dirty http server [written in python] I use something like
> this:
> from BaseHTTPServer import HTTPServer
> from SimpleHTTPServer import SimpleHTTPRequestHandler
> HTTPServer(('', 8000), SimpleHTTPRequestHandler).serve_forever()
> For what you're asking about you'd probably want to use the
> CGIHTTPRequestHandler from the CGIHTTPServer module instead.  Check out

This is what i was after, thanks for the tip.

> Then you'd just write one or more cgi scripts (they can be in python
> IIRC) to run the commands you want.

Im having trouble running the following cgi script on windows


#!c:/Python/python.exe -u

text = """Content-type: text/html

<H1>A Second CGI script</H1>
<P>Hello, CGI World!</P>
print text


using this http server from


import CGIHTTPServer
import BaseHTTPServer

class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
    cgi_directories = ["/cgi"]

PORT = 8000

httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT


i get the error number 403, when i try to access the cgi script which
is located in a subdirectory called cgi where this file is (http
server). I have a feeling that i need to change the Handler class or
something, implement , but i couldnt find any examples other then this
from eff-bot.

It could also be this line of code, that a google search turned up, its
the way of running cgi scripts on windows

#!c:/Python/python.exe -u


More information about the Python-list mailing list