2016-12-26 134 views
0

我正在嘗試將鉤子附加到路由。儘管我遵循文檔中的代碼,但是一些錯誤和鉤子返回錯誤,無論我在裏面做什麼。TypeError:do_before()缺少1個需要的位置參數:'resp'

部件/ 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) 

當運行此使用gunicorn和請求localhost:8000/counter,它返回:

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

回答

1

正確的語法是

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

您需要傳遞一個實例,而不是引用該對象。

+0

哇,有一段時間沒有工作,但只是取得舊代碼,它的工作原理!謝謝。 –

相關問題