[英]Python social auth Django pipeline nonetype errors
I have the following pipleline in my Django settings file for Facebook login with python-social-auth module: 我在Django设置文件中使用python-social-auth模块进行Facebook登录时有以下pipleline:
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.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.get_username',
'social.pipeline.user.user_details',
'social.pipeline.social_auth.associate_by_email',
)
My login method looks like that: 我的登录方法如下:
When I try to authenticate for the first time with Facebook I'm getting the following: AttributeError at /complete/facebook/ 'NoneType' object has no attribute 'provider' 当我第一次尝试使用Facebook进行身份验证时,我得到以下内容:/ error / facebook /'NoneType'对象中的AttributeError没有属性'provider'
def user_login(request):
""" Login page view."""
#context = RequestContext(request)
context = RequestContext(request,
{'request': request,
'user': request.user})
user = request.user
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password) # authentication
if not user.is_anonymous():
print user
if not request.method == 'POST':
user.backend = 'django.contrib.auth.backends.ModelBackend'
if user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
return render_to_response('main/login.html', {}, context)
else:
return render_to_response('main/login.html', {}, context)
However, if I comment out SOCIAL_AUTH_PIPELINE and try to login, then it's fine. 但是,如果我注释掉了SOCIAL_AUTH_PIPELINE并尝试登录,那就没关系了。 Of course, once a social auth user is in a database the Pipleline is working correctly. 当然,一旦社交认证用户在数据库中,Pipleline就能正常工作。
I would appreciate any ideas where to look for a bug. 我很感激任何寻找错误的想法。
This is probably not your cause, because in my case I got this error whatever pipeline was, but it may help someone else. 这可能不是你的原因,因为在我的情况下,无论管道是什么,我都会得到这个错误,但它可能会帮助别人。
In my case I got this error, because I deleted user from auth_user
table, but there still existed record in social_auth_usersocialauth
table pointing to non-existent user id which prevented from creating record with correct user. 在我的情况下,我收到此错误,因为我从auth_user
表中删除了用户,但在social_auth_usersocialauth
表中仍然存在指向不存在的用户ID的记录,该用户ID无法使用正确的用户创建记录。 That was solved in my case either by deleting record from social_auth_usercoaialauth
table or fixing that record to point to existing user id. 在我的情况下,通过从social_auth_usercoaialauth
表中删除记录或将该记录修复为指向现有用户ID来解决这个问题。
Try to add this setting : SOCIAL_AUTH_ALWAYS_ASSOCIATE = True 尝试添加此设置:SOCIAL_AUTH_ALWAYS_ASSOCIATE = True
It seems that your user is not linked to the social profile. 您的用户似乎未链接到社交个人资料。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.