-1
curl -i -H "Content-Type: application/json" -X POST -d '{"message": 
"test"}' http://localhost:5000/members

This is my old code which was working as a command (returns a 200). now i want to write a python skript for that using requests. I am trying this:

header = {"Content-type": "application/json"}
r = requests.post("http://127.0.0.1:5000/members", data={"message": "test"}, headers=header) 

Which returns an 400. Why? How can i fix that? Its btw a flask rest api running on that port.

davidism
  • 121,510
  • 29
  • 395
  • 339
Niwla23
  • 103
  • 14

1 Answers1

1

Your trying to send the data without actually combining it. You just need to surround the {} with '.

header = {"Content-type": "application/json"}
r = requests.post("http://127.0.0.1:5000/members", data='{"message": "test"}', headers=header)
Drath Gull
  • 56
  • 1
  • 5