I have 1 small program. I'm sending the request of json via CURL X POST and should get the answer. The client code is:
curl -XPOST -d'{"animal":"cow", "sound":"moooo", "count": "3"}' 192.168.88.88:5000/test
The server code is:
import json
from flask import Flask, request, jsonify
app = Flask(__name)
@app.route("/test", methods=['POST'])
def json_example():
content = request.get_json(silent=True)
animal = content["animal"]
sound = content["sound"]
count = str(content["count"])
i=0
res=''
while i<int(count):
temp = animal + "says " + sound +"\n"
res = temp +res
i = i + 1
return res
app.run(host='0.0.0.0', port = 5000)
If I'm running the request at postman and indicating that this is json type - then all is OK, but if I'm running it via curl - has an error (None type object isn't subscriptable) Please advice, how to correct the code at server and indicate, that all responses will be type of json.
Thanks