仿照Tornado.web.authenticated写了个decorator
def authenticated_api(method):
@
functools.wraps(method)
def wrapper(self, *args, **kwargs):
if not self.current_user:
raise HTTPError(401) # <-----
return method(self, *args, **kwargs)
return wrapper
然后就报错了……
Traceback (most recent call last):
File "/Users/merlin/linkworld/platform/venv/lib/python2.7/site-packages/tornado/web.py", line 1218, in _when_complete
callback()
File "/Users/merlin/linkworld/platform/venv/lib/python2.7/site-packages/tornado/web.py", line 1239, in _execute_method
self._when_complete(method(*self.path_args, **self.path_kwargs),
File "/Users/merlin/linkworld/platform/smartagriiotplatform/libs/utils.py", line 58, in wrapper
raise HTTPError(401)
TypeError: __init__() takes exactly 6 arguments (2 given)
看了一下,HTTPError并没有要求6个参数啊!而且`Tornado.web.authenticated`这么做,也工作得好好的。