Tags Python

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)
httpd.serve_forever()

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