我希望添加一个falcon.before挂钩,如下所示:
def check_authenticated(request, response, resource, params):
print(request.headers)
request.context.test = 'test'
@falcon.before(check_authenticated)
class testing(object):
async def on_get(self, request, response):
print(request.headers)
print('made it here')但是我一直在面对错误:TypeError: object NoneType can't be used in 'await' expression
发布于 2021-03-23 02:07:09
通过您的on_get响应器的异步签名(async def),我假设您使用的是框架的ASGI型。在这种情况下,不仅您的响应器,而且中间件方法,钩子,接收器,错误处理函数都必须是可等待的协程函数。
比较和对比这个"more complex example"的WSGI和ASGI版本,在同步和异步两种风格的框架中,falcon.before都应用了钩子。
TL;DR您需要将钩子更改为async def check_authenticated(...)。
https://stackoverflow.com/questions/65458556
复制相似问题