AttributeError at /social-auth/NoneType/github/ 'NoneType‘对象没有属性'provider’
这个网站上的其他解决方案没有解决这个问题。抱歉,如果你把这当成dup的话。
复制自reddit:
你好!希望大家都做得好。正如标题所示,每当我尝试在我的网站上使用社交登录时,我都会收到这个错误。这是一所学校,我们正在使用github作为授权。我认为正在发生的是,用户的社交数据被发送到其他地方,而不是用户的社交网络数据库。我认为这是因为在github创建了我的帐户并崩溃之后,我可以看到它在数据库中正确地抓取了我的用户名和来自github的电子邮件,我可以在我的管理员中看到它。然而,用户的社交空间仍然是空的,我很有信心,我的urlpatterns将数据重定向到该死的sun而不是用户社交创作数据库有问题。再说一次,我不知道怎么解决这个问题。我已经做了两个星期了,在解决这个问题上没有取得任何进展,
我尝试过的事情:
Social_auth_pipeline,这不管用
使用django_allauth使站点崩溃
我已经改变了我的设置几十次,是的,上下文在那里,应用程序被安装,我有正确的重定向
我已经改变了我的习惯很多次了,似乎没有什么区别
我从其他有同样问题的人那里添加了代码,但没有解决这个问题
我已经删除了代码,更多的是为了查看哪些是实际工作的,哪些是不工作的
链接到网站。这样你就可以看到实际的问题了
https://rakunana.pythonanywhere.com
所有的代码也在我的github上。所以,可以自由地挖掘代码。
https://github.com/RakuNana/School_Site
我的urls.py代码:
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')添加我的回溯:
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'提前感谢!
发布于 2022-05-02 19:24:34
解决了。问题就出在Pythonanywhere和Github身上。免费帐户不能获得出站请求!当社交请求试图获取用户数据时,它将始终不返回任何数据!这是因为数据从未被发送回Django应用程序。在我自己的机器上,用我自己的本地主机进行测试,相同的代码在没有任何更改的情况下完美地工作。总之,由于任何原因,Pythonanywhere和Github没有正确地相互提供信息,或者他们完全屏蔽了这些信息。不知道为什么,但是,我可以使用社交软件,没有问题,在我自己的机器。
https://stackoverflow.com/questions/71981746
复制相似问题