Access Request Parameters in invoked script of Python CGIHTTPServer

598 views Asked by At

A python script of mine is successfully invoked from CGIHTTPServer. How may we access the request parameters within that script?

I have done a number of rounds of googling on this topic. I am not in a position to do mod-cgi on an Apache server for example. Apache is not running on the box - nor will it be. it is not my box and that is too big of a change to make.

If the answer is "there is no ready-made solution to accessing request parameters in a (python actually..) cgi script" - then is there another option for built-in python web server that can do cgi (with request parameters) ? Along the lines of java servlets ..

1

There are 1 answers

2
WestCoastProjects On BEST ANSWER

Within the cgi script I added (temporarily) the following code to find the environment variables:

import os
v = [i for i in os.environ.iteritems()]
pl('env is %s' %(repr(v)))

Within the rather copious output is included the answer being sought:

('QUERY_STRING', 'cpus=128&cpumillis=60') 

Then the query parameters are easily obtained as:

qs={k:v for k,v in [l.split('=') for l in os.environ['QUERY_STRING'].split('&')]}