Solution: using the FieldStorage in .asp pages under IIS

Max M maxm at
Thu Dec 20 11:32:55 CET 2001

Some months back I asked how to use the FieldStorage under the IIS using
Python in .asp. But nobody seemed to know.

Well I got sidetracked for a while, but got back to it today and found the
solution by readin through the cgi source. So here's the solution.

regards Max M

<% @Language = "Python" %>

def winFieldStorage(Request):

    from StringIO import StringIO

    from cgi import FieldStorage

    # get the relevant enviroment variables from the IIS
    env = {}
    for key in keys:
        env[key] = str(Request.ServerVariables(key))

    # get the content from the Request as binary
    binaryContent, size = Request.BinaryRead(int(env['CONTENT_LENGTH']))
    # tempfile in memory
    fp = StringIO(str(binaryContent))
    fs = FieldStorage(fp=fp, environ=env)
    return fs

fs = winFieldStorage(Request)

Response.Write('Keys: ' + str(fs.keys()))


More information about the Python-list mailing list