Django登录 - 获取AttributeError无法设置属性

时间:2012-06-29 20:32:41

标签: django mongodb attributeerror

每次尝试登录Django网站的本地副本时,我都会收到以下错误:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/users/process_login/

Django Version: 1.4
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'tweets',
 'users',
 'dashboard',
 'GChartWrapper.charts',
 'api',
 'prospector',
 'viz')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/sheldonc/Tealeaf/users/views.py" in process_login
  184.             login(request, user)
File "/Library/Python/2.7/site-packages/django/contrib/auth/__init__.py" in login
  71.         request.session.cycle_key()
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/base.py" in cycle_key
  241.         self.create()
File "/Library/Python/2.7/site-packages/mongoengine-0.6.1-py2.7.egg/mongoengine/django/sessions.py" in create
  44.             self.session_key = self._get_new_session_key()

Exception Type: AttributeError at /users/process_login/
Exception Value: can't set attribute

和例外位置:

Exception Location: /Library/Python/2.7/site-packages/mongoengine-0.6.1-py2.7.egg/mongoengine/django/sessions.py in create, line 44

使用pdb,我进一步调试了它。在login(request, user)方法中:

def login(request, user):
 56         """
 57         Persist a user id and a backend in the request. This way a user doesn't
 58         have to reauthenticate on every request. Note that data set during
 59         the anonymous session is retained when the user logs in.
 60         """
 61         if user is None:
 62             user = request.user
 63         # TODO: It would be nice to support different login methods, like signed cookies.
 64         if SESSION_KEY in request.session:
 65             if request.session[SESSION_KEY] != user.id:
 66                 # To avoid reusing another user's session, create a new, empty
 67                 # session if the existing session corresponds to a different
 68                 # authenticated user.
 69                 request.session.flush()
 70         else:
 71             request.session.cycle_key()

SESSION_KEY为None,因此调用了request.session.cycle_key(),并且在那里出现了AttributeError被抛出(

这是我的mongo连接的问题吗?我一直在四处寻找,但我似乎无法弄清楚这一点

1 个答案:

答案 0 :(得分:0)

已知(且已修复)错误:https://github.com/hmarr/mongoengine/issues/469