[Medusa-dev] RE: Medusa CGI requests

Kevin Smith smithk at attbi.com
Fri Dec 20 20:10:43 EST 2002

Using the CGI module (FieldStorage class) with Medusa....

I have been able to use the cgi module with medusa but needed to recreate
some of the necessary information that medusa had consumed in the request

try this in your python script....
    from cgi import FieldStorage
    #FieldStorge default is to get the header info from enviroment variables
    #we can override this in the constructor of the FieldStorage class
    #the FieldStorage headers object must be a dictionary if it is
    #the Medusa request.header will need to be converted into a

    #create an empty dictionary object
    dicHeader = {}
    #break the request.header tuple apart...
    for varPart in request.header:
        #break each reqest header part apart into key/values pairs
	varKeyValuePair= varPart.split(": ")
	#Place them in the dictionary

    # create another dictionary to act as the enviroment variables
    dicEnvir = {}
    #Add the Request Method from the request object
    dicEnvir['REQUEST_METHOD'] = request.command

    #break up the request uri into parts...
    [path, params, query, fragment] = request.split_uri()

    #put the query string in the dictionary...
    dicEnvir['QUERY_STRING'] = query
    #create a FieldStorage object with overridden headers and environ object
    form = FieldStorage(fp=stdin,headers=dicHeader,environ=dicEnvir)

    if form.has_key("user"):
        print "user = %s" % form["user"].value

I have been using this with HTML form data that is posted like so....
<FORM action="cgi-bin/test.mpy" enctype="application/x-www-form-urlencoded"
method="post" name="submitform">
<INPUT type="text" name="user">
<INPUT type="submit" name="continue" value="Continue">

good luck

More information about the Medusa-dev mailing list