Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Python as a CGI script without the CGI module?

Tags:

python

cgi

Is it possible to use Python as CGI without using the CGI module and still get access to all of the browser information and everything?

I tried:

#!/usr/bin/python
import sys
print "Content-type: text/html"
print
data = sys.stdin.readlines()
print len(data)

but it always prints 0.

like image 421
kilometer Avatar asked Sep 06 '25 03:09

kilometer


1 Answers

It is indeed possible, but a lot of the information is passed in as environment variables, not on standard input. In fact, the only thing that is passed in on standard input is the body of the incoming request, which would only have contents if a form is being POSTed.

For more information on how to work with CGI, check a website such as http://www.w3.org/CGI/. (It's too much to explain the entire standard in an answer here)

like image 189
David Z Avatar answered Sep 07 '25 21:09

David Z