Chris Kraszewski
Chris Kraszewski

Reputation: 690

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'

Upvotes: 3

Views: 1728

Answers (1)

Angwen
Angwen

Reputation: 134

The correct syntax is

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

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

Upvotes: 7

Related Questions