-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Twitter backend error with Python 3.3 #139
Comments
I can confirm - error still there... Python 3.3.3, Django 1.6.1 Stacktrace (most recent call last):
File "django/core/handlers/base.py", line 201, in get_response
response = middleware_method(request, response)
File "django/contrib/sessions/middleware.py", line 38, in process_response
request.session.save()
File "django/contrib/sessions/backends/db.py", line 57, in save
session_data=self.encode(self._get_session(no_load=must_create)),
File "django/contrib/sessions/backends/base.py", line 87, in encode
serialized = self.serializer().dumps(session_dict)
File "django/core/signing.py", line 88, in dumps
return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "json/__init__.py", line 243, in dumps
**kw).encode(obj)
File "json/encoder.py", line 191, in encode
chunks = self.iterencode(o, _one_shot=True)
File "json/encoder.py", line 249, in iterencode
return _iterencode(o, 0)
File "json/encoder.py", line 173, in default
raise TypeError(repr(o) + " is not JSON serializable") |
Could you share your pipelines? |
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'bemycobase.pipeline.require_email_username_birthdate_sex_city',
# 'social.pipeline.mail.mail_validation',
'bemycobase.pipeline.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
) from datetime import datetime
import traceback
from account.models import EmailAddress
from django.contrib import messages
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from social.pipeline.partial import partial
import sys
@partial
def require_email_username_birthdate_sex_city(strategy, details, user=None,
is_new=False, *args, **kwargs):
if user and user.email and user.username and user.first_name \
and user.last_name and user.birthdate and user.sex \
and user.city:
return
elif is_new and (not details.get('email') or not details.get('username')
or not details.get('first_name')
or not details.get('last_name')
or not details.get('birthdate') or not details.get('sex')
or not details.get('city_id')):
if strategy.session_get('saved_email') and \
strategy.session_get('saved_username') and \
strategy.session_get('saved_first_name') and \
strategy.session_get('saved_last_name') and \
strategy.session_get('saved_birthdate') and \
strategy.session_get('saved_sex') and \
strategy.session_get('saved_city_id'):
details['email'] = strategy.session_pop('saved_email')
details['username'] = strategy.session_pop('saved_username')
details['first_name'] = strategy.session_pop('saved_first_name')
details['last_name'] = strategy.session_pop('saved_last_name')
details['birthdate'] = strategy.session_pop('saved_birthdate')
details['sex'] = strategy.session_pop('saved_sex')
details['city_id'] = strategy.session_pop('saved_city_id')
else:
return redirect(
'bemycobase:require_email_username_birthdate_sex_city')
def create_user(strategy, details, response, uid, user=None, *args, **kwargs):
if user:
return
fields = dict((name, kwargs.get(name) or details.get(name))
for name in strategy.setting('USER_FIELDS'))
if not fields:
return
fields['birthdate'] = datetime.strptime(details.get('birthdate'),
'%Y-%m-%d')
try:
created_user = strategy.create_user(**fields) # commit=False,
# prevent User post_save signal from creating an Account instance
# we want to handle that ourself.
# created_user._disable_account_creation = True
created_user.username = details.get('username')
created_user.save()
# created_email = EmailAddress.objects.add_email(created_user,
# created_user.email,
# **{'primary': True,
# 'verified': False,
# 'confirm': True})
# Account.create(request=strategy.request, user=created_user,
# create_email=False)
email_address = EmailAddress.objects.get(user=created_user,
email=created_user.email)
email_address.send_confirmation()
messages.add_message(
strategy.request,
messages.INFO,
_("Confirmation email sent to {email}.").format(**{
"email": details.get("email")
})
)
return {
'is_new': True,
'user': created_user
}
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
debug = ''.join('!! ' + line for line in lines) |
But you can ignore my custom pipelines because of I can't associate my current user account with Twitter too... |
@lorddaedra, could you try again with the last reviesion on master? |
@omab tested trunk, it works fine... (before I used latest pip) |
Cool, I'm gonna release it. Thanks! |
Thanks! I used something similar to your fix for a temporary workaround angkot/angkot@b43d07a |
I'm getting the same error on Master now, with the Facebook OAuth backend. |
Right now when you use .content, the token is bytes, not text, and so you run into an error when saving it to the session. Similar error in issue omab#139.
(Perhaps this also affects all OAuth1 based backends)
I got the following error
The error arises when Django saves the session data (encoded in JSON) that contains that unauthorized token from Twitter. The type of the token is byte so the
json
module refuses to encode it. I see that the token value is retrieved from therequests
module.Other libs that are also installed in my setup:
The text was updated successfully, but these errors were encountered: