AttributeError at / account / login / oauth / complete / facebook / Object 'NoneType' has no attribute 'userprofile'

I have a problem: instead of user information "User" Facebook is using "NoneType", so I cannot save the image as extended user model information (userprofile) after the first facebook social authentication.

If any further information is needed, please let me know.

settings.py:

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id,name,email',
}

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
    'ridemaker.pipeline.save_profile',
)

      

pipeline.py:

from accounts.models import UserProfile
from social_core.backends.facebook import FacebookOAuth2, FacebookAppOAuth2
from urllib.request import urlopen
from django.template.defaultfilters import slugify
from django.core.files.base import ContentFile

def save_profile(backend, details, response, uid,\
              user, *args, **kwargs):
    if backend.__class__ == FacebookOAuth2:
        url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
        avatar = urlopen(url)
        #Why is user argument "None"?
        profile = user.userprofile
        profile.image.save(slugify(user.username + " social") + '.jpg',
                        ContentFile(avatar.read()))
        profile.save()

      

+3


source to share


1 answer


You are overriding options SOCIAL_AUTH_PIPELINE

and you skipped the pipeline social_core.pipeline.user.create_user

that creates the user. Place below two pipelines after social_core.pipeline.social_auth.social_user

in SOCIAL_AUTH_PIPELINE

:



'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',

      

0


source







All Articles