gpt4 book ai didi

python - python 社交身份验证中缺少 session 状态

转载 作者:行者123 更新时间:2023-11-28 16:19:52 27 4
gpt4 key购买 nike

我遵循了本教程 ( https://artandlogic.com/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/ ),但出现了以下错误。我在 EC2 实例上托管了我的服务器,并且我有一个域 http://(xyz).com .我也看到了这个问题的答案(Session value missing after redirect with django python-social-auth),但我没有得到任何帮助。 enter image description here

这是文本中的堆栈跟踪

 AuthStateMissing at /api/user/complete/google-oauth2/
Session value state missing.
Request Method: GET
Request URL: http://interviewmiles.com:8000/api/user/complete/google-oauth2/?state=9Sa5JSkbcAbbGzBtqpx6jtbLCuJPe6kJ&code=4/c4VTig14u7THYLd1M4VoTRf1dnq58wp6S68EbkSwhZs&authuser=0&session_state=8aa4e419c219643dc264950a24151457677d99ae..b805&prompt=none
Django Version: 1.9.7
Exception Type: AuthStateMissing
Exception Value:
Session value state missing.
Exception Location: /usr/local/lib/python2.7/site-packages/social/backends/oauth.py in validate_state, line 88
Python Executable: /usr/bin/python
Python Version: 2.7.10
Python Path:
['/home/ec2-user/interviewmiles/login',
'/usr/local/lib/python2.7/site-packages/django_cors_headers-1.1.0-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/local/lib64/python2.7/site-packages',
'/usr/local/lib/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages',
'/usr/lib/python2.7/site-packages',
'/usr/lib64/python2.7/dist-packages',
'/usr/lib64/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages']

/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
response = self.process_exception_by_middleware(e, request) ...

▶ Local vars
/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py in _wrapped_view_func
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/django/views/decorators/csrf.py in wrapped_view
return view_func(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/apps/django_app/utils.py in wrapper
return func(request, backend, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/apps/django_app/views.py in complete
redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/actions.py in do_complete
user = backend.complete(user=user, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/backends/base.py in complete
return self.auth_complete(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/utils.py in wrapper
return func(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/backends/oauth.py in auth_complete
state = self.validate_state() ...
▶ Local vars
/usr/local/lib/python2.7/site-packages/social/backends/oauth.py in validate_state
raise AuthStateMissing(self, 'state')

最佳答案

我设法通过设置最终解决了这个问题

SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

在我的 settings.py 文件中。

我的生产服务器使用 nginx 将 HTTP 重定向到 HTTPS,这就是 session 状态丢失的原因。祝您好运——希望这对您有所帮助!

关于python - python 社交身份验证中缺少 session 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41197081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com