raise HTTPError(401),这么简单的操作,怎么会报 TypeError?

2014-05-05 10:45:42 +08:00
 merlinran
仿照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`这么做,也工作得好好的。
3255 次点击
所在节点    Python
1 条回复
merlinran
2014-05-05 11:03:57 +08:00
解决了,同事的低级错误

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/111182

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX