Search code examples
pythonflaskflask-restful

Flask restful GET doesn't respond within app


I have a flask restful api with an endpoint

api.add_resource(TestGet, '/api/1/test')

and I want to use the data from that endpoint to populate my jinja template. But everytime I try to call it in a sample route like this

@app.route('/mytest') def mytest(): t = get('http://localhost:5000/api/1/test') It never returns anything and stays in a loop meaning it is doing something with the request and never returns. Is there a reason I am not able to call it within the same flask app? I am able to reach the endpoint on the browser and from another python REPL. Thoroughly confused why this would happen and why it never returns anything. At least expecting an error.

Here is the entire sample of what I am trying to run

from flask import Flask
from requests import get

app = Flask('test')

from flask_restful import Api, Resource

api = Api(app)

class TestGet(Resource):
    def get(self):
        return {'test': 'message'}

api.add_resource(TestGet, '/test')

@app.route('/something')
def something():
    resp = get('http://localhost:5000//test').json
    print(resp)
from gevent.wsgi import WSGIServer
WSGIServer(('', 5000), app).serve_forever()

Solution

  • Use app.run(threaded=True) if you just want to debug your program. This will start a new thread for every request.