Python 属性错误位于/account/login/oauth/complete/facebook/';非类型';对象没有属性';用户配置文件';
我有一个问题,Facebook帐户信息不是“用户”,而是“非类型”类型,因此在首次Facebook社交身份验证后,我无法将图像保存为扩展用户模型信息(userprofile) 如果需要任何其他信息,请通知我 设置。py:Python 属性错误位于/account/login/oauth/complete/facebook/';非类型';对象没有属性';用户配置文件';,python,django,facebook,python-social-auth,django-socialauth,Python,Django,Facebook,Python Social Auth,Django Socialauth,我有一个问题,Facebook帐户信息不是“用户”,而是“非类型”类型,因此在首次Facebook社交身份验证后,我无法将图像保存为扩展用户模型信息(userprofile) 如果需要任何其他信息,请通知我 设置。py: SOCIAL_AUTH_FACEBOOK_SCOPE = ['email'] SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { 'fields': 'id,name,email', } SOCIAL_AUTH_PIPELINE
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',
)
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()
pipeline.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',
)
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()
您正在覆盖设置中的
SOCIAL\u AUTH\u管道
,并且错过了创建用户的管道SOCIAL\u core.PIPELINE.user.create\u user
。在social\u auth\u pipeline
中的social\u core.pipeline.social\u auth.social\u user
后面放置两条管道:
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',