Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Not Receiving Data from HTTP POST [duplicate]

Tags:

flask

I'm working on my first POST method route in my API. For some reason when I pass variables to it via url http://test.com/test?stuff=wee, Flask throws errors like stuff didn't make it through.

Code:

@app.route('/test', methods = ['POST'])
def testindex():

    stuff = request.args.get('stuff')

    response_message = "success"
    response_data = stuff
    errors = "None"
    response = {
        'response message' : response_message,
        'response data': response_data,
        'errors' : errors
    }

    js = json.dumps(response)
    resp = Response(js, status=200, mimetype='application/json')
    return resp

cURL:

curl -H "Content-Type: application/json" -X POST -d '{"stuff":"wee"}' http://test.com/test?stuff=wee

response:

{"errors": "None", "response data": null, "response message": "success"}

Help?

like image 357
Josh Usre Avatar asked Feb 05 '26 19:02

Josh Usre


1 Answers

request.args.get is for getting parameters from GET. You'll want request.form.

like image 164
Celeo Avatar answered Feb 09 '26 04:02

Celeo