推荐学习书目
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 · May 5, 2014 · 4074 views
    This topic created in 4399 days ago, the information mentioned may be changed or developed.
    仿照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`这么做,也工作得好好的。
    merlinran
        1
    merlinran  
    OP
       May 5, 2014
    解决了,同事的低级错误
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1401 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:11 · PVG 01:11 · LAX 10:11 · JFK 13:11
    ♥ Do have faith in what you're doing.