http - can I get the POST data from environment variables in python? -


i trying understand http queries , succesfully getting data requests through environment variables first looking through keys of environment vars , accessing 'query_string' actual data.

like this:

#!/usr/bin/python3 import sys import cgi import os  inputvars = cgi.fieldstorage()  f = open('test','w') f.write(str(os.environ['query_string])+"\n") f.close() 

is there way post data (the equivalent of 'query_string' post - say) or not accessible because post data send in own package? keys of environment variables did not give me hint far.

the possible duplicate link solved it, syntonym pointed out in comments , user schien explains in 1 of answers linked question:

the raw http post data (the stuff after query) can read through stdin. sys.stdin.read() method can used.

my code works looking this:

#!/usr/bin/python3 import sys import os  f = open('test','w') f.write(str(sys.stdin.read())) f.close() 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -