I am trying to retrieve data from url into json format using flask-restplus.
from flask import Flask, render_template
import requests
import json
from flask_restplus import Resource, Api, fields
from flask_sqlalchemy import SQLAlchemy
# config details
COLLECTION = 'indicators'
app = Flask(__name__)
api = Api(
app,
title='Akhil Jain',
description='Developing ' \
'a Flask-Restplus data service that allows a client to ' \
'read and store some publicly available economic indicator ' \
'data for countries around the world, and allow the consumers ' \
'to access the data through a REST API.'
)
@api.route('/indicators')
def get(self):
uri = 'http://api.worldbank.org/v2/indicators'
try:
res = requests.get(uri)
print(res)
return res.json()
except:
return False
if __name__ == '__main__':
app.run(debug=True)
but after trying out the GET, the response i am getting is False instead of the json data. Could anyone tell me how to get the response data so that i can process it to sqllite db.
Thanks
return res.json()would raise an Exception which would make your app responseFalse