Skip to content

injector._BindingNotYetAvailable: name 'Response' is not defined #66

Closed
@jsr1337

Description

@jsr1337

Hello,
based on code from this post: #40 injector throws the above error. My code is almost identical, the only difference is flask_restful instead of flask_restplus:

from flask import Flask
from flask_restful import Api, Resource
from flask_injector import FlaskInjector, inject, singleton

app = Flask(name)
app.secret_key = "123"
api = Api(app=app)

class MyConf():
def init(self, val: int):
self.val = val

class MyApi(Resource):
@Inject
def init(self, conf: MyConf, **kwargs): # <- here just added **kwargs to receice the extra passed api parameter
self.val = conf.val
# Don't know if really needed
super().init(**kwargs)

def get(self, conf: MyConf):
    return {'x': conf.val}, 200

api.add_resource(MyApi, '/myapi')

def configure(binder):
binder.bind(
MyConf,
to=MyConf(456),
scope=singleton
)
# No need to bind the resource itself
#binder.bind(
# MyApi,
# to=MyApi(myConf)
#)

FlaskInjector(app=app, modules=[configure])

app.run(port=555, debug=True)

Am I doing something wrong here or this is a bug?
My setup:
Flask==2.0.1
Flask-HTTPAuth==4.4.0
Flask-Injector==0.12.3
Flask-JWT==0.3.2
Flask-RESTful==0.3.9
typing-extensions==3.7.4.3
typing-inspect==0.6.0
injector==0.18.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions