Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print all POST request parameters without knowing their names

How can I print all parameters that were passed in with a POST request using Python and flask?

I know how to ask for a parameter by name

from flask import  request
key = request.args.get('key')

But i'm not sure why this did not work for me:

for a in request.args:
        print "argument: " + a
like image 943
Alex Stone Avatar asked Aug 20 '14 17:08

Alex Stone


1 Answers

request.args returns a MultiDict. It can have multiple values for each key. In order to print all parameters, you can try:

The code below works for URLs with parameters added,like:

 http://www.webservice.my/rest?extraKey=extraValue
    multi_dict = request.args
    for key in multi_dict:
        print multi_dict.get(key)
        print multi_dict.getlist(key)

For parameters embedded within the POST request as a form:

dict = request.form
for key in dict:
    print 'form key '+dict[key]

See the example here and you will have a good idea.

like image 82
codegeek Avatar answered Oct 13 '22 02:10

codegeek