Local execution of Python CGI scripts – with Python 3

January 14th, 2011 at 5:46 pm

A while ago I wrote about executing CGI scripts in Python locally using the built-in web server in the standard library. Here is a short port of that script to Python 3:

from http.server import HTTPServer, CGIHTTPRequestHandler

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

PORT = 9999

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

The only real difference is the way the HTTP server classes are called and where they’re imported from.

Related posts:

  1. Local execution of Python CGI scripts
  2. Problem passing arguments to Python scripts on Windows
  3. Sending mail from Python with SMTP
  4. A “live” data monitor with Python, PyQt and PySerial
  5. pyelftools ported to Python 3

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)