python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

__init__() I'm encountering an error: "got multiple values for argument 'X'" #617

Closed KeithYatco closed 2 months ago

KeithYatco commented 2 months ago

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. A clear and concise question

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.products_namespace = self.api.namespace(
      'api/products', 
      description='products endpoint'
    )

self.products_namespace.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

self.api.add_namespace(self.products_namespace)
KeithYatco commented 2 months ago

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):