I used django_openid_auth
on my project and it worked quite alright for some time.
But today, I tested the application and came across this exception:
Environment:
Request Method: GET
Request URL: http://localhost:7777/google/login/
Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'meet',
'django_openid_auth',
'django_jenkins')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware',
'meet.middlewares.TimezoneMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
201. response = middleware_method(request, response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/middleware.py" in process_response
38. request.session.save()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/db.py" in save
57. session_data=self.encode(self._get_session(no_load=must_create)),
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/backends/base.py" in encode
87. serialized = self.serializer().dumps(session_dict)
File "/usr/local/lib/python2.7/dist-packages/django/core/signing.py" in dumps
88. return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/usr/lib/python2.7/json/__init__.py" in dumps
238. **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py" in encode
201. chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py" in iterencode
264. return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py" in default
178. raise TypeError(repr(o) + " is not JSON serializable")
Exception Type: TypeError at /google/login/
Exception Value: <openid.yadis.manager.YadisServiceManager object at 0x7fd2f43b2250> is not JSON serializable
I'm not sure what other info should I provide, but I do have my auth.py
here:
from django.contrib.auth.models import User
from openid.consumer.consumer import SUCCESS
from django.core.mail import mail_admins
class GoogleBackend:
def authenticate(self, openid_response):
if openid_response is None:
return None
if openid_response.status != SUCCESS:
return None
google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
google_firstname = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.firstname')
google_lastname = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.lastname')
try:
#user = User.objects.get(username=google_email)
# Make sure that the e-mail is unique.
user = User.objects.get(email=google_email)
if user.first_name == u'' :
user.first_name = google_firstname
if user.last_name == u'' :
user.last_name = google_lastname
except User.DoesNotExist:
user = User.objects.create_user(google_email, google_email, 'password')
user.first_name = google_firstname
user.last_name = google_lastname
user.save()
user = User.objects.get(username=google_email)
return user
return user
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
and also urls.py
contains these two lines:
url(r'^google/login/$', 'django_openid_auth.views.login_begin', name='openid-login'),
url(r'^google/login-complete/$', 'django_openid_auth.views.login_complete', name='openid-complete'),
Then again, upon request for logging in, the exception just pops out. And if that helps, the only thing changed is I started using django 1.6 for my site. could anyone advise?
This seems to be a known bug: https://bugs.launchpad.net/django-openid-auth/+bug/1252826
However, as of now, there doesn't seem to be a fix.
The workaround, as per this comment, is to reset the serializer:
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
YEP! I checked!
as I was telling, it was because of new version of django,
I migrated back to 1.5.5
and everithing works fine again!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With