Part of my Flask code:
@app.route('/api/post', methods=['POST'])
def post():
body = request.get_json()
json_body = json.loads(body)
new_id = mongo.db.Projects.insert(json_body)
return str(new_id)
Script to post a new database entry:
payload = { 'ProjectName' : 'KdB Test Project' }
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
r = requests.post('http://localhost:5000/api/post', headers=headers, data=json.dumps(payload))
I keep getting json decoder TypeError problems, e.g.
TypeError: expected string or buffer
2016-08-16 15:19:31,388 - werkzeug - INFO - 127.0.0.1 - - [16/Aug/2016 15:19:31] "POST /api/post HTTP/1.1" 500 -
I have tried several things, incl. posting strings. Any clue what is wrong with the way I post a dictionary? The problem appears to be at the point of body = request.get_json(). I don't think I am picking up any data...