cgi.parse from stdin problem

newbie spam at pleasedontspam.de
Mon Jan 28 07:53:11 EST 2002


Hello, please could someone correct my understanding of the following?

I wish to treat the contents of a file (coming from stdin) as cgi arguments,
but I cannot get the cgi.parse function to work. I guess I'm doing something
wrong. This is not going to be a cgi script, I just have some data in cgi
format.

If I have a `print record' in the while loop, the data is shown to be coming
in okay. My problem is that `fields' is always empty and I don't understand
why. I've tried replacing cgi.parse(record) with
cgi.parse(sys.stdin.readline()) and have the same results.

Here's the relevant part of the script:


#!/usr/bin/python2

import string, sys, cgi

record = sys.stdin.readline()
while record != "":
        fields = cgi.parse(record)
        for fieldname in fields.keys():
                print fieldname

        record = sys.stdin.readline()


stdin supplies the data in `item1=value1&item2=value2' format.

Anyone see my mistake? I've tried using cgi.FieldStorage() too with no
success even though I've used it before with real cgi. :-(

Any help appreciated.
T.





More information about the Python-list mailing list