V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
merlinran
V2EX  ›  Python

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

  •  
  •   merlinran ·
    merlinran · 2014-05-05 10:45:42 +08:00 · 3223 次点击
    这是一个创建于 3616 天前的主题,其中的信息可能已经有所发展或是发生改变。
    仿照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`这么做,也工作得好好的。
    1 条回复
    merlinran
        1
    merlinran  
    OP
       2014-05-05 11:03:57 +08:00
    解决了,同事的低级错误
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2834 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:53 · PVG 22:53 · LAX 07:53 · JFK 10:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.