1

I have the following flask route:

@app.route('/change_groups', methods = ['POST'])
def change_groups():
  if not request.json:
    return "Not a json post"
  return "json post!"

When I curl like this I get back "Not a json post" as expected:

curl --data "param1=value1&param2=value2" localhost:8000/change_groups

I then try to post json to trigger the "json post!" code:

curl -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:8000/change_groups

The second request also triggers "Not a json post" when I was expecting "json post!".

How can I similate posting json to this Flask route?

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

2 Answers2

2

In your request you don't set Content-Type: application/json, so it won't be parsed as JSON.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
1

Found answer quickly, needed to add header data:

-H "Content-Type: application/json"
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225