瓶子应用的Cork认证问题:TypeError("'NoneType'对象不支持项赋值",)
我在用Cork库和Bottle应用程序时遇到了一些问题。我尝试设置示例应用程序,并做了一些小改动让它能在WSGI容器中运行。主要的改动是我把这个:
if __name__ == "__main__":
main()
改成了这个:
application = default_app()
当我用管理员用户进行身份验证时,我得到了以下内容:
Traceback (most recent call last):
File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 763, in _handle
return route.call(**args)
File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 1572, in wrapper
rv = callback(*a, **ka)
File "/path_to_app/cork-example/simple_webapp.py", line 47, in login
aaa.login(username, password, success_redirect='/', fail_redirect='/login')
File "build/bdist.linux-x86_64/egg/cork/cork.py", line 209, in login
self._setup_cookie(username)
File "build/bdist.linux-x86_64/egg/cork/cork.py", line 610, in _setup_cookie
session['username'] = username
TypeError: 'NoneType' object does not support item assignment
当我尝试查看主页时,我遇到了这个错误:
Traceback (most recent call last):
File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 763, in _handle
return route.call(**args)
File "/path_to_app/lib/python2.7/bottle-0.11.4-py2.7.egg/bottle.py", line 1572, in wrapper
rv = callback(*a, **ka)
File "/path_to_app/cork-example/simple_webapp.py", line 90, in index
aaa.require(fail_redirect='/login')
File "build/bdist.linux-x86_64/egg/cork/cork.py", line 267, in require
cu = self.current_user
File "build/bdist.linux-x86_64/egg/cork/cork.py", line 417, in current_user
username = session.get('username', None)
AttributeError: 'NoneType' object has no attribute 'get'
我是不是犯了什么新手错误?还是说其他地方出了问题?
1 个回答
0
我搞明白了。这是个新手错误。Bottle的文档里说,如果你想用Bottle和mod_wsgi一起工作,在文件的最后部分,你应该使用这个:
application = default_app()
在我更好地理解这一切是怎么运作之后,我意识到我把错误的应用对象发送给了mod_wsgi。其实,我应该使用这个:
application = app #app was defined earlier in the example application