Shamoon
Shamoon

Reputation: 43491

Why won't my Flask function return a JSONified array?

I have:

@application.route('/prediction', methods=['POST'])
def create_predictions():
    ...
    print(alternatives)
    print(jsonify(alternatives, 201))

    return jsonify(alternatives, 201)

alternatives is a list of strings. When I print the jsonify, I get:

<Response 8800 bytes [200 OK]>

When I post data to the endpoint, I get {} as a response. What am I doing wrong?

Upvotes: 0

Views: 85

Answers (1)

bruhmoment
bruhmoment

Reputation: 98

Judgin from the <Response 8800 bytes [200 OK]> that you get i think you're using requests.get(url) to get the response. Or you're trying to print it which you can't so just try to actually request it

Instead try using this to see the returned json:

import requests
requests.get(url).json()

And also the status code is suppposed to returned outside the parentheses like this:

return jsonify(alternatives), 201

Upvotes: 2

Related Questions