python-social-auth Twitter登录返回Authenitcation失败

时间:2017-02-24 16:06:14

标签: python django twitter python-social-auth

我尝试使用python-social-auth通过Google,Facebook和Twitter注册和登录用户(最初)。谷歌和Facebook正在运作,但在Twitter上我收到了以下错误:

  

在/ login / twitter /

身份验证失败      

身份验证失败:('握手不好:SysCallError(0,无)',)

这里是追溯:

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)',)

我的HTML链接是:

<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 个答案:

答案 0 :(得分:0)

我做了两件事(我不知道是哪个解决了这个问题)似乎对此进行了整理。 (注意:我已经标记了这些块引用,因为它没有显示为代码,因为它不可读)

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