Sunday 1 August 2021

Flask-Limiter is not called on Flask-Restful API's method_decorators

I've tried to follow some questions with no luck:

Due to outside of context issue I created a limiter function in a util.py file as follow:

def limiter():
    _limiter = Limiter(
        app,
        key_func=get_remote_address
    )
    return _limiter

And in my Flask-Restful API resource I have called this limiter in method-decorators:

from ..utils import limiter

class UsersView(Resource, CustomAPIMixin):
     method_decorators = [limiter().limit("1/minute", methods=["GET"])]

     @jwt_authenticate()
     def get(self):
         user_id = get_jwt_identity()
         return self.api_response(content={"user_id": user_id})

NOTE: I'm using Flask version 2 and Flask-Limiter 1.4



from Flask-Limiter is not called on Flask-Restful API's method_decorators

No comments:

Post a Comment