24

So I just got my first django app deployed.

I did a syncdb and created my superuser account for the site.

Now when I access the page and press the login button I get this error. I think it has something to do with the password but I'm not sure.

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

I'm using the generic login view

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

The following is the traceback

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
bash-
  • 6,144
  • 10
  • 43
  • 51

6 Answers6

33

Just had the same problem.

It seem that in my case, the site was running with Django 1.4 when the password was created (due to a PYTHONPATH mix-up).

When I tried to login running the site with 1.3.1 I got this error. Then I noticed the Django version, switched to 1.4 and the login started working again.

It seems the password algorithm was changed in 1.4:

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

And if you were using Django 1.4 alpha it might also be that the password was effectively corrupted (read the warning).

h3.
  • 10,688
  • 15
  • 51
  • 54
18

The easiest fix is to reset your password from the command line.

./manage.py changepassword <user>
Travis Bear
  • 13,039
  • 7
  • 42
  • 51
12

You can reset the password in the shell.

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

This happens when we downgrade from 1.4.X to test old deployments as detailed by @h3.

Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
11

Yes, there is a problem in the password.

The error is in the way the password has been encrypted and stored in the DB. It can be clearly seen from the statement algo, salt, hsh = enc_password.split('$') in the traceback. The encrypted password splitting returns more than 3 values.

So, please have look at the password encryption schemes and related.

Sandip Agarwal
  • 1,890
  • 5
  • 28
  • 42
  • Why is that though? I just did a `syncdb` and created a user when prompted. Also I just looked at the pw hash there's 3 `$`... so that would split into 4... – bash- Jan 21 '12 at 16:23
  • I found out what the problem is. I messed up the secret key when I was fiddling with the settings. thanks – bash- Jan 21 '12 at 16:29
  • Strange. I am getting exactly the same exception. I changed my secret-key but I am still getting same error. – Burak Mar 14 '12 at 18:34
  • 11
    @Burak you probably are setting the password in the shell with a different version of django than the one the server is using. – fastmultiplication Apr 03 '12 at 14:43
  • This is exactly the same error that I have been encountering did anyone find any solutions for this? cause I was thinking of modifying that part right there but it's not really a good idea and I hate to mess up with the django core code – Christopher Pelayo Apr 28 '12 at 03:10
  • 2
    See http://stackoverflow.com/a/10223206/380623 my issue was a Django 1.4 vs 1.3 mismatch. – nix Nov 08 '12 at 16:51
2

I did everything to solve the same problem. Finally I deleted the db tables, and made syncdb again, creating new superuser. Everything works fine now. The problem is related to bad user data I guess.

Burak
  • 5,706
  • 20
  • 70
  • 110
0

I had a similar problem. The password for my superuser was somehow corrupted. You can check this by examining the auth_user table in your database. Your password should be something like ""sha1$263a7$c17f83f1d1902fb7bd527d00ffcb22f4dc97a978". If you have more than (or less than) two "$" symbols, you would get a similar error. The reason for this, as Sandip mentioned, is because the following function expects three values to be returned:

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

Having that extra "$" symbol in your password would return four values and cause the "too many values to unpack" error message to appear.

The solution for me was to create a new superuser by using the createsuperuser command in the manage.py script. More information about how to create a superuser can be found here:

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

I am still not sure why my password was corrupted.

asdf
  • 1
  • I also had this issue. I started with Django 1.4 and then reverted to 1.3 to maintain compatibility with Grappelli. I created my superuser when I installed 1.4 and the default password pattern does not look like it is backwards compatible with 1.3. Deleting my superuser and creating a new one worked for me. – Kieran Lynn Mar 25 '12 at 14:58