Python 社交身份验证 Django 管道非类型错误

标签 python django pipeline python-social-auth

我的 Django 设置文件中有以下 pipleline,用于使用 python-social-auth 模块登录 Facebook:

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',
)

我的登录方法是这样的:

当我第一次尝试使用 Facebook 进行身份验证时,我得到以下信息: /complete/facebook/处的属性错误 'NoneType' 对象没有属性 '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)

但是,如果我注释掉 SOCIAL_AUTH_PIPELINE 并尝试登录,那就没问题了。当然,一旦社交身份验证用户进入数据库,Pipleline 就会正常工作。

我将不胜感激任何在哪里寻找错误的想法。

最佳答案

这可能不是你的原因,因为在我的例子中,无论管道是什么,我都会遇到这个错误,但它可能对其他人有帮助。

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

关于Python 社交身份验证 Django 管道非类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29144394/

相关文章:

django - Django 的工作日

部署时的 Django 静态文件问题

java - Jython 和 python 模块

c++ - 速度——在 C++ 中嵌入 Python 或使用 C++ 扩展 Python

python - 百日草启动问题

Azure DevOps 如何跳过 PR 构建运行的 PublishBuildArtifacts 步骤

r - 如何比较r中管道中的行数?

python - 质数和 - for 循环和大数

python - matplotlib 中的背靠背直方图

c# - NUnit 如何将屏幕截图附加到 Azure Pipeline 中的测试附件