Solution: using the FieldStorage in .asp pages under IIS

Max M maxm at normik.dk
Thu Dec 20 05:32:55 EST 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" %>
<html>
<head>
    <title>Test</title>
</head>
<body>
<%

def winFieldStorage(Request):

    from StringIO import StringIO

    from cgi import FieldStorage

    # get the relevant enviroment variables from the IIS
    env = {}
    keys = ('CONTENT_TYPE','CONTENT_LENGTH',
            'QUERY_STRING','REQUEST_METHOD')
    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)
    fp.close()
    return fs

fs = winFieldStorage(Request)

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

%>
</body>
</html>





More information about the Python-list mailing list