0

I need to get the body of a POST request with Content-Type: application/x-www-form-urlencoded in a Connexion API handler. The accepted answer here suggests to use request.get_data(), however this always returns just b'' for me. My guess is that Connexion parses the data before request.get_data() gets called and that is causing the issue.

How do I get the raw request payload in this case? If there's no way to get it directly, how do I properly reconstruct it from request.form (which seems to contain the parsed data)?

planetp
  • 12,388
  • 16
  • 74
  • 140

2 Answers2

0

I'm not sure if there's an easier way, but this seems to do the trick:

import urllib.parse

form_data = request.form
request_data = '&'.join([k + '=' + urllib.parse.quote_plus(v) for k, v in form_data.items()])
planetp
  • 12,388
  • 16
  • 74
  • 140
0
from connexion import request

type(request.form)
# <class 'werkzeug.datastructures.ImmutableMultiDict'>
print(dict(request.form))
Song
  • 499
  • 8
  • 19