使用Bottle app的Cork身份验证时遇到问题:TypeError(“'NoneType'对象不支持项目分配”,)

时间:2013-02-11 18:32:00

标签: python authentication wsgi bottle

我在使用Bottle应用程序实现Cork库时遇到了一些麻烦。我已经尝试设置示例应用程序,并进行了一些小修改以使其在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 :(得分:0)

我明白了。这是一个新手的错误。 Bottle文档说如果你想在文件的末尾使用带mod_wsgi的Bottle,你应该使用它:

application = default_app()

在更好地理解了这一切是如何工作之后,我意识到我向mod_wsgi发送了错误的应用程序对象。相反,我应该用这个:

application = app #app was defined earlier in the example application