pythonfalconframework

TypeError: do_before() missing 1 required positional argument: 'resp'


I'm trying to attach a hook to a route. Although I'm following the code in documentation, something is wrong and hook returns error no matter what I do inside it.

components/counter.py:

def auth_request(req, resp, resource, params):
    pass


@falcon.before(auth_request)
class Counter(object):
    def on_get(self, req, resp):
        pass

app.py:

import falcon
from components import counter

api = application = falcon.API()

api.add_route('/counter', counter.Counter)

When I run this using gunicorn and request localhost:8000/counter, it returns:

TypeError: do_before() missing 1 required positional argument: 'resp'


Solution

  • The correct syntax is

    api.add_route('/counter', counter.Counter() )

    You need to pass an instance, not reference to the object.