response = requests.get(url) response_json = response.json() results = response_json['a'][0] output = results['a_1'] + results['a_2'] + results['a_3'] return jsonify(output)
my output "abcdefg"
what I want abcdefg
How should I fix it?
jsonify builds a Flask Response object. With this code you're trying to access it as if it was a dictionary:
jsonify
results = jsonify( response_json )["results"][0] # bad
I think you're looking for:
results = jsonify( response_json["results"[0] )
Note that here response_json is actually a python datastructure (a dictionary) because that's what response.json returns.
response_json
response.json
jsonify
builds a Flask Response object. With this code you're trying to access it as if it was a dictionary:I think you're looking for:
Note that here
response_json
is actually a python datastructure (a dictionary) because that's whatresponse.json
returns.