Python社交auth Django管道非类型错误

use*_*565 2 python django pipeline python-social-auth

我在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',
)
Run Code Online (Sandbox Code Playgroud)

我的登录方法如下:

当我第一次尝试使用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)
Run Code Online (Sandbox Code Playgroud)

但是,如果我注释掉了SOCIAL_AUTH_PIPELINE并尝试登录,那就没关系了.当然,一旦社交认证用户在数据库中,Pipleline就能正常工作.

我很感激任何寻找错误的想法.

K.H*_*.H. 6

这可能不是你的原因,因为在我的情况下,无论管道是什么,我都会得到这个错误,但它可能会帮助别人.

在我的情况下,我得到了这个错误,因为我从auth_user表中删除了用户,但是表中仍然存在social_auth_usersocialauth指向不存在的用户ID的记录,这阻止了用正确的用户创建记录.在我的情况下,通过从social_auth_usercoaialauth表中删除记录或修复该记录以指向现有用户ID来解决这个问题.