cgi module question

Jeff Shipman shippy at nmt.edu
Fri Apr 26 18:49:13 EDT 2002


Whew. Thanks for telling me about StringIO! I
was getting ready to open pipes and stuff...

Just to make sure, this is the code I'm using.
Please tell me if I'm making any incorrect
assumptions:

# Grab query string and process form
if os.environ['REQUEST_METHOD'] == 'POST':
    qs = sys.stdin.readline()
    sio = StringIO.StringIO(qs)
    form = cgi.FieldStorage(sio)
    sio.close()
else:
    qs = os.environ['QUERY_STRING']
    form = cgi.FieldStorage()


Thanks again.

Ian Bicking wrote:
> On Fri, 2002-04-26 at 15:45, Jeff Shipman wrote:
> 
>>Uh, no, not really because it's consumed by
>>FieldStorage(). If I consume it before that, then
>>there's FieldStorage() can't grab it. I still
>>need to use the cgi module, but I also need
>>to get the POST query string.
> 
> 
> You can read in the POST string, and then pass it to the cgi module (as
> a file-like object with StringIO).  There's an optional argument to
> FieldStorage -- look at the source to find it.
> 
>   Ian
> 
> 
> 


-- 
Jeff "Shippy" Shipman     E-Mail: shippy at nmt.edu
Computer Science Major    ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy




More information about the Python-list mailing list