Answer the question
In order to leave comments, you need to log in
Why does request.json return null in flask?
good time.
I am making a POST request. Actually the code.
from flask import Flask
from flask import jsonify, request
app = Flask(__name__)
@app.route('/api/func/<int:id>/', methods=['POST'])
def func(id):
data = request.json
return jsonify(data)
app.run(...)
curl -i -X POST -d "{'data': 'some_data'}" http://IP:PORT/api/func/<id>/
Answer the question
In order to leave comments, you need to log in
Everything is ok, the problem is in the cURL request itself
Set the content-type to JSON
-H "Content-Type: application/json"
Plus, as it seems to me, not a curl expert, but it would be better to wrap JSON in a single quote, and wrap all the data inside in a double quote, since a single quote is not correct in JSON .
In theory, this is how it should work on Linux.
curl -i -X POST -d '{"data": "some_data"}' -H "Content-Type: application/json" http://127.0.0.1:5000/api/func/1/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question