all Python 3until 3.15Removed from the standard libraryterm
http.server.CGIHTTPRequestHandler
removed
An http.server handler that ran CGI scripts. Removed in Python 3.15 — move to WSGI (wsgiref) or a web framework.
Syntax
http.server.CGIHTTPRequestHandler # до 3.15
CGIHTTPRequestHandler served files like SimpleHTTPRequestHandler and ran scripts from /cgi-bin and /htbin as a separate process per request; on the command line it was enabled by python -m http.server --cgi. It was removed together with the flag: CGI fell out of use long ago and nobody maintained the code. To migrate, turn the script body into a WSGI application — a function app(environ, start_response) that reads parameters from environ and returns a list of bytes. During development run it with wsgiref.simple_server.make_server('', 8000, app).serve_forever(); in production use any WSGI server or framework.
Examples
# Python 3.15+
import http.server
try:
http.server.CGIHTTPRequestHandler
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.15+
from wsgiref.util import setup_testing_defaults
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [f"hello from {environ['PATH_INFO']}".encode()]
environ = {}
setup_testing_defaults(environ)
print(b''.join(app(environ, lambda status, headers: None))) # → b'hello from /'
from http.server import CGIHTTPRequestHandler, SimpleHTTPRequestHandler
print(issubclass(CGIHTTPRequestHandler, SimpleHTTPRequestHandler)) # → True
print(CGIHTTPRequestHandler.cgi_directories) # → ['/cgi-bin', '/htbin']
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy