Python Forum
Flask rest api How to retrieve json request
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask rest api How to retrieve json request
#1
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_data
On 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.
Reply
#2
I think it is something about postman.
Reply
#3
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.
Reply
#4
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.
Reply
#5
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  API Request / JSON illmattic 3 911 Aug-01-2023, 10:14 AM
Last Post: Gaurav_Kumar
  REST API using flask - limit connection? korenron 1 1,210 Feb-05-2023, 06:48 PM
Last Post: noisefloor
  Flask Rest API - fire and forget MorganSamage 2 1,534 Feb-04-2023, 11:09 AM
Last Post: MorganSamage
  Flask TypeError: Object of type Decimal is not JSON serializable mekacharan 0 3,888 Jul-15-2021, 05:28 AM
Last Post: mekacharan
  Flask Basics request.form ifigazsi 0 1,783 Feb-09-2021, 09:05 AM
Last Post: ifigazsi
  Flask request.form ifigazsi 2 3,571 Feb-02-2021, 11:56 AM
Last Post: buran
  Retrieve images base64 encoded MongoDB and Flask Nuwan16 2 3,233 Oct-13-2020, 06:25 PM
Last Post: Nuwan16
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 1,826 May-11-2020, 04:58 PM
Last Post: jenkins43
  Simple flask rest api problem cancerboi 4 2,782 Jan-29-2020, 03:10 PM
Last Post: brighteningeyes
  Flask redirect(request.url) returns None iFunKtion 1 10,418 Nov-27-2018, 10:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020