Flask rest api How to retrieve json request - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Flask rest api How to retrieve json request (/thread-14363.html) |
Flask rest api How to retrieve json request - raysefo - Nov-26-2018 Hello, I am new to Python. I have a flask rest api. I am trying to call another rest api inside of my method. I would like to know if there is a way to get json request data when my method is called? Here is my code portion: # POST /purchase_initiation @app.route('/purchase_initiation', methods=['POST']) def initiation(): try: # if request.is_json: # getting request data request_data = request.json() print request_dataOn the Print I am getting 'NoneType' object is not callable error. By the way I am sending POST request from POSTMAN. Thanks in advance. Best Regards. RE: Flask rest api How to retrieve json request - raysefo - Nov-26-2018 I think it is something about postman. RE: Flask rest api How to retrieve json request - micseydel - Nov-27-2018 Can you provide your Postman request as a curl? I imagine this is because either you're not sending JSON, or you're not specifying the content type as JSON. RE: Flask rest api How to retrieve json request - Shalinimittal - Dec-04-2018 I understand the question, you were definitely set the content type as JSON instead of sending JSON. Try to send JSON and also provide the postman request. RE: Flask rest api How to retrieve json request - raysefo - Jan-20-2019 This solved my problem; # POST /purchase_initiation @app.route('/purchase_initiation', methods=['POST']) def initiation(): try: # getting request data request_data = request.form.to_dict() |