我一直试图让python-social-auth正常工作,而我得到的只是错误Client Error: Bad Request
,它完全无法帮我调试情况。在我的研究中,我发现了一些错误here,但没有真正的迹象表明 如何解决它。 This问题也解决了这个问题,但同样,指向同一个没有真正解决方案的GitHub线程。
我似乎无法弄清正在进行什么。它似乎正在尝试完成身份验证过程,但在/complete/facebook/
失败了。这是跟踪:
Environment:
Request Method: GET
Request URL: http://23.239.3.97:8000/complete/facebook/?redirect_state=big_long_string_of_letters_and_numbers_i_removed_for_security
Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ms',
'users',
'south',
'social.apps.django_app.default')
Installed Middleware:
('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')
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper
52. return func(request, backend, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py" in complete
20. redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/actions.py" in do_complete
43. user = backend.complete(user=user, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in complete
40. return self.auth_complete(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py" in auth_complete
69. 'code': self.data['code']
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in get_querystring
229. return parse_qs(self.request(url, *args, **kwargs).text)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in request
222. response.raise_for_status()
File "/usr/lib/python2.7/dist-packages/requests/models.py" in raise_for_status
773. raise HTTPError(http_error_msg, response=self)
Exception Type: HTTPError at /complete/facebook/
Exception Value: 400 Client Error: Bad Request
以下是相关的settings.py
信息:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
)
AUTHENTICATION_BACKENDS = (
'social.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_FACEBOOK_KEY = '***' #replaced actual with *** for security
SOCIAL_AUTH_FACEBOOK_SECRET = '***' #replaced actual with *** for security
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_URL = '/login/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/logged-in/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login-error/'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'email']
SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
'social.backends.facebook',
)
SOUTH_MIGRATION_MODULES = {
'default': 'social.apps.django_app.default.south_migrations',
}
django dev服务器返回500错误代码,因此它是我猜测的内部内容。我把头发拉出来!有什么想法吗?
答案 0 :(得分:0)
当我在Facebook的应用设置中未能设置正确的回调网址时,我遇到了类似的错误。您必须在应用的高级设置中指明“http://www.yourdomain.com/login/facebook”回调网址。希望这会有所帮助。