Returning HTTP POST body from CGI module
Stephen
shriek at gmx.co.uk
Sun Nov 25 19:55:49 EST 2001
> > I have a Python CGI script receiving XML data via HTTP POST from
> > another company. Unfortunately, that company doesn't seem to
> > have implemented the HTTP protocol correctly.
>
> This is completely valid HTTP. They probably ought to have
> Content-Type header in there, but it's no big deal.
Thank you for putting me straight on this one. Since web browsers
seem to send urllib.quote_plus()'ed text, I guess that the web server
is urllib.unquote()'ing everything it receives. So, whether you send
quoted or unquoted text it will become the same thing.
> CGI request content comes in on stdin. The cgi lib just
> parses it. The headers tend to show up in the environment,
> but I'm not sure any old header you send shows up
> there...
>
> The following program should give you access to the data though:
>
> #!/usr/bin/python
> import sys, os
> length = os.environ["CONTENT_LENGTH"]
> print sys.stdin.read(length)
Excellent, works a treat ~ using sys.stdin.read(int(length)) ~ and
thanks for explaining how CGI request content is transfered via stdin.
I had been wondering how the data was transfered to Apache.
Thanks Michal,
Stephen.
More information about the Python-list
mailing list