web programming variable description remote_ident remote_user request_method script_name user making the request authenticated username method ('getor 'post'name of the program server host name server port number server protocol name and version of the server software server_name server_port server_protocol server_software as outputa cgi program writes to standard output sys stdout the gory details of cgi programming can be found in book such as cgi programming with perl nd editionby shishir gundavaram ( 'reilly associates for our purposesthere are really only two things to know firstthe contents of an html form are passed to cgi program in sequence of text known as query string in pythonthe contents of the query string are accessed using the fieldstorage class for exampleimport cgi form cgi fieldstorage(name form getvalue('name'email form getvalue('email'get 'namefield from form get 'emailfield from form secondthe output of cgi program consists of two partsan http header and the raw data (which is typically htmla blank line always separates these two components simple http header looks like thisprint 'content-typetext/html\rprint '\rhtml output blank line (required!the rest of the output is the raw output for exampleprint 'my cgi scriptprint 'hello world!print 'you are % (% )(nameemailit is standard practice that http headers are terminated using the windows lineending convention of '\ \nthat is why the '\rappears in the example if you need to signal an errorinclude special 'status:header in the output for exampleprint 'status forbidden\rhttp error code print 'content-typetext/plain\rprint '\rblank line (requiredprint 'you're not worthy of accessing this page!if you need to redirect the client to different pagecreate output like thisprint 'status moved\rprint 'locationprint '\rmost of the work in the cgi module is performed by creating an instance of the fieldstorage class fieldstorage([input [headers [outerboundary [environ [keep_blank_values [strict_parsing]]]]]]read the contents of form by reading and parsing the query string passed in an environment variable or standard input input specifies file-like object from which form lib fl ff