Django Social Auth-Google:AttributeError:“ NoneType”对象没有属性“ provider”

我尝试通过Google登录时收到此错误,我已经尝试了所有我能想到的问题,因此类似的问题似乎无济于事。我有这样的自定义用户模型设置:

models.py

from django.contrib.auth.models import AbstractUser
from django.db import models
class Departments(models.Model):
    name = models.CharField(max_length=255,unique=True)
    def __str__(self):
        return self.name

class AlluredUser(AbstractUser):
    departments = models.ManyToManyField(Departments)
    def __str__(self):
        return self.username  

forms.py

from django import forms
from django.contrib.auth.forms import UserCreationForm,UserChangeForm
from .models import AlluredUser

class CustomUserCreationForm(UserCreationForm):

    class Meta:
        model = AlluredUser
        fields = ('username','email')

class CustomUserChangeForm(UserChangeForm):

    class Meta:
        model = AlluredUser
        fields = ('username','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.user.get_username','social_core.pipeline.social_auth.associate_by_email','social_core.pipeline.user.create_user','social_core.pipeline.social_auth.associate_user','social_core.pipeline.social_auth.load_extra_data','social_core.pipeline.user.user_details'
)

错误回溯

AttributeError at /auth/complete/google-oauth2/
'NoneType' object has no attribute 'provider'

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/auth/complete/google-oauth2/?state=8XLcbxz6sPSPOwJfOIXWOud88UJ5YtL2&code=4/twHRVLHTMzBV99K-VvektvJfjGuJYGBvqi254dWTuA2dLmbNFw3fIp8l5pdYSqKK89ONPGrxInG39pH8Wf-fpas&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email%20openid&authuser=0&hd=allured.com&session_state=2403f8348307b18b8ab460026d3c88b1b18d759f..5dbb&prompt=none

Django Version: 2.2.4
Python Version: 3.7.4
Installed Applications:
['user.apps.UserConfig','issue_tracker.apps.IssueTrackerConfig','ytd_reports.apps.YtdReportsConfig','stats.apps.StatsConfig','scheduler.apps.SchedulerConfig','submissions.apps.SubmissionsConfig','dash_app.apps.DashAppConfig','contact.apps.ContactConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.humanize','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','social_django']
Installed Middleware:
['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.Sessionmiddleware','django.middleware.common.Commonmiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.Authenticationmiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','social_django.middleware.SocialAuthExceptionmiddleware','dashboard.middleware.loginRequired.LoginRequiredMiddleware']



Traceback:

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e,request)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request,*callback_args,**callback_kwargs)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request,*args,**kwargs)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
  54.         return view_func(*args,**kwargs)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\social_django\utils.py" in wrapper
  49.             return func(request,backend,**kwargs)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\social_django\views.py" in complete
  33.                        *args,**kwargs)

File "C:\Users\jsarko\AppData\Local\Programs\Python\Python37-32\lib\site-packages\social_core\actions.py" in do_complete
  71.                                          social_user.provider)

Exception Type: AttributeError at /auth/complete/google-oauth2/
Exception Value: 'NoneType' object has no attribute 'provider'

我猜想这与我创建的自定义用户模型有关,因为我事先没有这个问题。任何帮助将不胜感激。

riijlcvyp 回答:Django Social Auth-Google:AttributeError:“ NoneType”对象没有属性“ provider”

链接上的错误与标题中提到的不匹配。 对于回溯,解决方案只是添加以下内容:

SESSION_COOKIE_SECURE = False
本文链接:https://www.f2er.com/2974749.html

大家都在问