Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse the "request body" using python CGI?

I just need to write a simple python CGI script to parse the contents of a POST request containing JSON. This is only test code so that I can test a client application until the actual server is ready (written by someone else).

I can read the cgi.FieldStorage() and dump the keys() but the request body containing the JSON is nowhere to be found.

I can also dump the os.environ() which provides lots of info except that I do not see a variable containing the request body.

Any input appreciated.

Chris

like image 958
Christopher Avatar asked Oct 01 '10 05:10

Christopher


1 Answers

If you're using CGI, just read data from stdin:

import sys
data = sys.stdin.read()
like image 79
ars Avatar answered Sep 16 '22 15:09

ars