I'm having trouble transitioning from flask_restful to flask_restx while using the add_resource() method. In flask_restful, everything was working fine, but I'm encountering issues with flask_restx.
Here are the relevant links to the documentation I’m following:
I'm encountering an error: "got multiple values for argument 'rate_limiter'".
I have tried removing rate_limiter from resource_class_kwargs, but the error persists. it will then ask got multiple values for argument "authentication".
Here’s the code snippet that is causing the issue:
from flask import Flask
from flask_restx import Api, Resource, reqparse
self.app = Flask(__name__)
self.api = Api(self.app, version='1.0', title='todo', description='todo')
self.ns = self.api.namespace('todo', description='todo')
self.ns.add_resource(ProductManagement, '/products/management/<string:id>', resource_class_kwargs={
'rate_limiter': self.rate_limiter,
'authentication': self.authentication,
'product_controller': self.product_controller
})
class ProductManagement(Resource):
def __init__(self, rate_limiter, authentication, product_controller):
self.result = []
self.parser = reqparse.RequestParser()
self.parser.add_argument('company_id', type=str)
self.rate_limiter = rate_limiter
self.authentication = authentication
self.product_controller = product_controller
I have fix the problem in the documentation it does not say that another object is also being passed in to the resources(ProductManagement) i just added a random variable:
def __init__(self, url, rate_limiter, authentication, product_controller):