I began using Flask and the AWS API Gateway at work for a public website we are building. I didn’t need to do any parameter mapping on the AWS side, so I went straight to work.

It turns out that Python Requests doesn’t send POST data as JSON by default and this had my head spinning as I was trying to figure out why the response was throwing an error.

This is the usual way of doing a POST request with Python Requests (notice the “data” variable):

r = requests.post(url, data={"key": "value"})

But API Gateway doesn’t like it by default, so switching that “data” with “json” does the trick. This tells Requests to send the POST data as JSON:

r = requests.post(url, json={"key": "value"})

Kudos to the answer found here. That’s it! I hope you find this useful in some way.







Leave a Comment

Your email address will not be published. Required fields are marked *