python-social-auth Twitter 登录 [=x11=] 身份验证失败

python-social-auth Twitter login returns Authenitcation Failed

我正在尝试使用 python-social-auth 通过 Google、Facebook 和 Twitter(最初)注册和登录用户。 Google 和 Facebook 正在运行,但在使用 Twitter 时出现以下错误:

AuthFailed at /login/twitter/

Authentication failed: ('bad handshake:SysCallError(0, None)',)

这是回溯:

Traceback:

File "/var/www/ian/env/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/var/www/ian/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/var/www/ian/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/www/ian/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/var/www/ian/env/lib/python2.7/site-packages/social_django/utils.py" in wrapper
  50.             return func(request, backend, *args, **kwargs)

File "/var/www/ian/env/lib/python2.7/site-packages/social_django/views.py" in auth
  19.     return do_auth(request.backend, redirect_name=REDIRECT_FIELD_NAME)

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/actions.py" in do_auth
  27.     return backend.start()

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/backends/base.py" in start
  34.             return self.strategy.redirect(self.auth_url())

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/backends/oauth.py" in auth_url
  166.         token = self.set_unauthorized_token()

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/backends/oauth.py" in set_unauthorized_token
  222.         token = self.unauthorized_token()

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/backends/oauth.py" in unauthorized_token
  246.             method=self.REQUEST_TOKEN_METHOD

File "/var/www/ian/env/lib/python2.7/site-packages/social_core/backends/base.py" in request
  222.             raise AuthFailed(self, str(err))

Exception Type: AuthFailed at /login/twitter/
Exception Value: Authentication failed: ('bad handshake: SysCallError(0, None)',)

我的HTMLlink通过了:

<a href="{% url 'social:begin' 'twitter' %}" class="btn btn-block btn-social btn-twitter"><span class="fa fa-twitter"></span>Sign in with Twitter</a>

我的urls.py是:

url(r'', include('social_django.urls', namespace='social')),
        

而我的 settings.py 有以下变化:

INSTALLED_APPS = [
    ...
    'social_django',
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ...
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]
AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_TWITTER_KEY = '6pdiYC2jCocUD7JarM0NbeGuR'
SOCIAL_AUTH_TWITTER_SECRET = 'Z2yTHmjB2jDvRSSXwJ0kFpAVjTn2UCsSJW8USIkQnGaVegzviw'

我认为我的错误在 settings.py 的某个地方,因为我在那里有几个其他的,但我找不到它。

请帮忙,我已经处理了 7 个小时,无法解决问题。

编辑

我真的不明白发生了什么,因为它突然开始在我的笔记本电脑上使用 django 开发服务器工作,但是当 运行 来自 VPS 时我继续收到错误。

编辑

如果我刷新屏幕两次(使用 F5 键),它就会登录!

我做了两件事(我不知道哪个解决了这个问题)似乎解决了这个问题。 (注意:我将这些标记为块引号,因为它不会以其他方式显示为代码并且因为不可读)

  1. 错误可能是由于内存不足导致的。交换文件排序
sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288 
sudo chmod 600 /swapfile 
sudo mkswap /swapfile 
sudo swapon /swapfile
  1. 将此添加到 Apache conf 文件
<Directory /var/www/path/to/wsgi>
    <Files wsgi.py>
        Require all granted
    </Files>
    WSGIApplicationGroup %{GLOBAL}
</Directory>