ValueError:解压缩Django的值过多

时间:2012-01-21 15:41:32

标签: python django

所以我刚刚部署了我的第一个django应用程序。

我做了syncdb并为该网站创建了我的超级用户帐户。

现在当我访问该页面并按下登录按钮时,我收到此错误。我认为这与密码有关,但我不确定。

ValueError at /accounts/login/
too many values to unpack

我正在使用通用登录视图

(r'^accounts/login/$', login, {'template_name': 'authentication/login.html'}),

以下是追溯

Environment:


Request Method: POST
Request URL: http://xx.xx.xx.xx:8888/accounts/login/?next=/some_page/

Django Version: 1.3.1
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',
 'django.contrib.admin',
 'bc_system_app',
 'django.contrib.humanize']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/views.py" in login
  35.         if form.is_valid():
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in is_valid
  121.         return self.is_bound and not bool(self.errors)
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in _get_errors
  112.             self.full_clean()
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in full_clean
  268.         self._clean_form()
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in _clean_form
  296.             self.cleaned_data = self.clean()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/forms.py" in clean
  85.             self.user_cache = authenticate(username=username, password=password)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py" in authenticate
  55.             user = backend.authenticate(**credentials)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in authenticate
  18.             if user.check_password(password):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in check_password
  275.         return check_password(raw_password, self.password)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in check_password
  42.     algo, salt, hsh = enc_password.split('$')

Exception Type: ValueError at /accounts/login/
Exception Value: too many values to unpack

6 个答案:

答案 0 :(得分:33)

遇到同样的问题。

在我的情况下,在创建密码时,该网站使用Django 1.4运行(由于PYTHONPATH混淆)。

当我尝试使用1.3.1登录运行网站时出现此错误。然后我注意到Django版本,切换到1.4并且登录再次开始工作。

似乎密码算法在1.4中已更改:

https://docs.djangoproject.com/en/dev/releases/1.4-beta-1/#improved-password-hashing

如果您使用的是Django 1.4 alpha,那么密码可能会被破坏(请阅读警告)。

答案 1 :(得分:18)

最简单的解决方法是从命令行重置密码。

./manage.py changepassword <user>

答案 2 :(得分:12)

您可以在shell中重置密码。

from django.contrib.auth.models import User
u = User.objects.get(username="myuser")
u.set_password("mypassword")
u.save()

当我们从1.4.X降级到测试@ h3详述的旧部署时会发生这种情况。

答案 3 :(得分:11)

是的,密码存在问题。

错误与密码加密并存储在数据库中的方式有​​关。从回溯中的语句algo, salt, hsh = enc_password.split('$')可以清楚地看到它。加密密码拆分返回的值超过3个。

因此,请查看密码加密方案及相关内容。

答案 4 :(得分:2)

我尽一切努力解决同样的问题。最后我删除了db表,并再次创建了syncdb,创建了新的超级用户。现在一切都很好。问题与我猜错的用户数据有关。

答案 5 :(得分:0)

我有类似的问题。我的超级用户的密码不知何故已损坏。您可以通过检查数据库中的auth_user表来检查这一点。你的密码应该是“”sha1 $ 263a7 $ c17f83f1d1902fb7bd527d00ffcb22f4dc97a978“。如果你有两个以上(或少于)两个”$“符号,你会得到一个类似的错误。正如Sandip所说,其原因是因为以下函数需要返回三个值:

algo, salt, hsh = enc_password.split('$')

在密码中加上额外的“$”符号将返回四个值,并导致出现“太多值解压缩”错误消息。

我的解决方案是使用manage.py脚本中的createsuperuser命令创建一个新的超级用户。有关如何创建超级用户的更多信息,请访问:

https://docs.djangoproject.com/en/dev/topics/auth/

我仍然不确定为什么我的密码已损坏。