简体   繁体   中英

Django social-auth-app-django error after social login completed

AttributeError at /social-auth/complete/github/ 'NoneType' object has no attribute 'provider'

Other solutions on this site did not solve the problem. Sorry if you see this as a dup.

copied from reddit:

Hello. Hope everybody is doing well. As the title suggest I keep getting this error every time I try to use the social login on my site. This is for a school and we are using github for the authorization, What I believe is happening is. the user social auth data is being sent somewhere else instead of the user social auth database, The reason I think this is because after github auths my account,and crashes, I can see it grabbed my user name and my email from github correctly in the database. I can see it in my admin, However. The user social auth remains empty.I'm pretty confident that there's a problem with my urlpatterns redirecting data into the damn sun instead of the user social auths database. Again I've got no idea how to fix this, I've been at it for about two weeks now and made no progress into solving this problem,

Things I've tried:

Social_auth_pipeline, dosen't work

using django_allauth crashes the site

I've changed my settings dozens of times, Yes the contexts are there, apps are installed, and I have the proper redirects

I've changed my urlpatterns dozens of times, doesn't seem to make a difference

I've added code from others that have had the same problem, didn't fix the issue

I've deleted code, more along the lines to see what actually was working and what wasn't

link to the website. So you can see the problem in action

https://rakunana.pythonanywhere.com

All the code is also on my github as well. So feel free to dig through the code.

https://github.com/RakuNana/School_Site

my urls.py code:

import os

from django.contrib import admin
from django.urls import include, path
from django.views.generic import TemplateView
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.views.static import serve


urlpatterns = [
    path('', TemplateView.as_view(template_name='home/main.html')),
    path('admin/', admin.site.urls),
    path('hello/',include('hello.urls')),
    path('polls/', include('polls.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('cats/' , include('cats.urls')),
    path('autos/', include('autos.urls')),
    path('ads/', include('ads.urls')),
    url('social-auth/', include('social_django.urls', namespace='social')),
]


# Serve the static HTML
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
urlpatterns += [
    url(r'^site/(?P<path>.*)$', serve,
        {'document_root': os.path.join(BASE_DIR, 'mysite'),
         'show_indexes': True},
        name='site_path'
        ),
]

# Serve the favicon - Keep for later
urlpatterns += [
    path('favicon.ico', serve, {
            'path': 'favicon.ico',
            'document_root': os.path.join(BASE_DIR, 'home/static'),
        }
    ),
]

try:
    from . import github_settings
    social_login = 'registration/login_social.html'
    urlpatterns.insert(0,
                       path('accounts/login/', 
auth_views.LoginView.as_view(template_name=social_login))
                  )
    print('Using', social_login, 'as the login template')
except:
    print('Using registration/login.html as the login template')

adding my traceback:

Environment:


Request Method: GET
Request URL: https://rakunana.pythonanywhere.com/social- 
auth/complete/github/? 
code=0788709ba858fa0f7d85&state=S40eDgNwuWgLXzEEwI1onpe3xUdNyHOu

Django Version: 3.2.5
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'polls.apps.PollsConfig',
 'home.apps.HomeConfig',
 'hello.apps.HelloConfig',
 'autos.apps.AutosConfig',
 'cats.apps.CatsConfig',
 'ads.apps.AdsConfig',
 'django_extensions',
 'crispy_forms',
 'django.contrib.humanize',
 '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']



Traceback (most recent call last):
  File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, 
**callback_kwargs)
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/django/views/decorators/cache.py", line 44, in 
_wrapped_view_func
    response = view_func(request, *args, **kwargs)
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/django/views/decorators/csrf.py", line 54, in 
wrapped_view
    return view_func(*args, **kwargs)
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/social_django/utils.py", line 49, in wrapper
    return func(request, backend, *args, **kwargs)
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/social_django/views.py", line 31, in complete
    return do_complete(request.backend, _do_login, 
user=request.user,
   File "/home/RakuNana/.virtualenvs/django3/lib/python3.8/site- 
packages/social_core/actions.py", line 73, in do_complete
    social_user.provider)

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

Thanks in advance!

Solved. The problem is with Pythonanywhere and Github. Free accounts can not get outbound request, When the social-auth request try's to get the users data, it will return None. ALWAYS, This is because that data is never sent back to the Django app, Tested on my own machine. with my own localhost, and the same code works perfectly without any changes. In conclusion, For whatever reason Pythonanywhere and Github aren't giving the information to each other properly or they are outright blocking that info. Don't know why but, I can use the social auth app without issue on my own machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM