For some reason I'm getting the error:
TypeError: search_products() takes at least 2 arguments (2 given)
The weird thing is that I make the same API call in two separate places -- one in a function which I placed in one of the Model classes. The other one in the page View. The one in the models class works fine, whereas the one in the View function is throwing back the error.
The following is my code in Views.py:
searchproducts=api.API().search_products(query="myproduct")
Again, when I write this exact same code in Models.py, all works fine.
My search_products function in the API class in api.py is as follows:
def search_products(self, category_id, query="", start=0, limit=10, filter=None, ranged_filters=None, sort_by=None):
How can I dig deeper to find the root of why this is happening?
Traceback:
/Users/me/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
return response
try:
response = callback(request, *callback_args, **callback_kwargs) ...
except Exception, e:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for middleware_method in self._exception_middleware:
response = middleware_method(request, e)
In your definition of search_products
you have category_id
as a required field, and you are not providing that as an argument when you are calling the method. Provide a default for category_id
or pass in the appropriate argument to resolve your issue