I am building a flask webapp that communicates with another application through http requests. So I am trying to using dependency injection for the httpClient object.
Here is the code
class HttpClient(object):
def __init__(self, host):
self.host = host
self.httpclient = 3partyModule.connect(url=host,
verbose=False,
max_greenlets=1)
def configure(binder):
binder.bind(HttpClient, to=HttpClient, scope=singleton)
if __name__ == '__main__':
app = Flask(__name__)
FlaskInjector(app=app, modules=[configure])
app.run()
When I run the application, I get the following error -
Exception has occurred: RuntimeError
Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
I have tried to lookup on this, but could not find any helpful lead. Appreciate if anyone can shed some light on the issue here.
Thank you in advance.
Package Versions:
Flask==2.0.1
Flask-Injector==0.12.3
Python==3.8