Support module for Common Gateway Interface (CGI) scripts.
This module defines a number of utilities for use by CGI scripts written in Python.
The global variable maxlen
can be set to an integer indicating the maximum size of a POST request. POST requests larger than this size will result in a Value Error being raised during parsing. The default value of this variable is 0
, meaning the request size is unlimited.
Availability: not Emscripten, not WASI.
This module does not work or is not available on WebAssembly platforms wasm32-emscripten
and wasm32-wasi
. See WebAssembly platforms for more information.
Introduction
A CGI script is invoked by an HTTP server, usually to process user input submitted through an HTML <FORM>
or <ISINDEX>
element.
Most often, CGI scripts live in the server’s special CGI-bin
directory. The HTTP server places all sorts of information about the request (such as the client’s hostname, the requested URL, the query string, and lots of other goodies) in the script’s shell environment, executes the script, and sends the script’s output back to the client.
The script’s input is connected to the client too, and sometimes the form data is read this way; at other times the form data is passed via the “query string” part of the URL. This module is intended to take care of the different cases and provide a simpler interface to the Python script. It also provides a number of utilities that help in debugging scripts, and the latest addition is support for file uploads from a form (if your browser supports it).
The output of a CGI script should consist of two sections, separated by a blank line. The first section contains a number of headers, telling the client what kind of data is following. Python code to generate a minimal header section looks like this: