How can I extract JSON data returned by Flask ?
back-end:
response_obj = {
'status': 'fail',
'message': 'Invalid Payload'
}
return jsonify(response_obj), 500
front-end:
import requests
data = # some json data here
response = requests.post('http://18.133.238.8/auth/login', json=data)
I've tried:
print(dir(response))
which gave me:
...
...
__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', '_next', 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'next', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url']
that tipped me off to use:
print(response.json)
or:
print(response.json())
I'm just getting errors. How do I get the JSON data from response ?