I'm trying to use python-social-auth to register and login users through Google, Facebook and Twitter (initially). Google and Facebook are working but with Twitter I'm getting the following error:
AuthFailed at /login/twitter/
Authentication failed: ('bad handshake:SysCallError(0, None)',)
Here's the traceback:
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)',)
My HTML link is through:
<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>
My urls.py
is:
url(r'', include('social_django.urls', namespace='social')),
And my settings.py
has the following changes:
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'
I think my error is somewhere in the settings.py
because I've had a couple of others in there, but I cannot find it.
Please help, I've been at this for 7 hours and can't work it out.
EDIT
I really do not understand what is going on because it has suddenly started working from my laptop using django development server but I continue to get the error when running from a VPS.
EDIT
And if I refresh the screen twice (using F5 key) it logs in!
I did two things (I do not know which solved the issue) which seems to have sorted this. (Note: I've marked these a blockquotes because it wasn't showing as code otherwise and because unreadable)
sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
<Directory /var/www/path/to/wsgi> <Files wsgi.py> Require all granted </Files> WSGIApplicationGroup %{GLOBAL} </Directory>