9

I'm trying to add a social media authentication to a website using Social-auth-app-django.

So I've created different apps for the most popular social media websites (Facebook, Twitter, Google+), and have set the callback url there.

But I'm coming across an error when I'm redirected back to the website from say Facebook:

    Internal Server Error: /oauth/complete/facebook/
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_django/utils.py", line 50, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_django/views.py", line 32, in complete
    redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/actions.py", line 41, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/base.py", line 40, in complete
    return self.auth_complete(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/utils.py", line 252, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/facebook.py", line 110, in auth_complete
    return self.do_auth(access_token, response, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/facebook.py", line 152, in do_auth
    return self.strategy.authenticate(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_django/strategy.py", line 115, in authenticate
    return authenticate(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/django/contrib/auth/__init__.py", line 74, in authenticate
    user = backend.authenticate(**credentials)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/base.py", line 80, in authenticate
    return self.pipeline(pipeline, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/base.py", line 83, in pipeline
    out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/social_core/backends/base.py", line 105, in run_pipeline
    for idx, name in enumerate(pipeline[pipeline_index:]):
TypeError: unhashable type: 'slice'

Below is a summary of how I've configured social_django:

In settings.py:

INSTALLED_APPS = [
    'social_django',
    ...
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.facebook.FacebookOAuth2',

    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_FACEBOOK_KEY = 'xxx'
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxx'

...

PIPELINE = {
    'PIPELINE_ENABLED': True,
    'STYLESHEETS': {...},
    'JAVASCRIPT': {...},
    'JS_COMPRESSOR': 'pipeline.compressors.NoopCompressor',
    'COMPILERS': (
        'pipeline.compilers.sass.SASSCompiler',
    )
}

Afterwards, I've obviously migrated the database to create the new tables.

Please find below the versions of Django and social_django:

  • Django: 1.10.5
  • social_django: 1.2.0

Regarding the pipeline used, I'm using django-pipeline but it's just for compiling SASS files to CSS.

What might cause this error?

Hakim
  • 2,479
  • 4
  • 33
  • 68
  • slice is of a mutable type (such as a list). So if you're trying to use that in the key of a dictionary then you'll get the unhashable type error – Alex S Jul 28 '17 at 17:31
  • You need to show your code, or at least the way you've configured python-social-auth. – Daniel Roseman Jul 28 '17 at 17:45
  • Please post more details like Django version, python-social-auth version, full traceback, custom configurations like custom pipeline, etc. – omab Jul 28 '17 at 20:17
  • I've just updated the question. Let me know if there's still some details to add. – Hakim Jul 28 '17 at 21:28
  • Do you see something missing in the configuration of the `python-social-auth`? – Hakim Aug 02 '17 at 17:14
  • Did you define pipeline in settihngs.py? – Kaushal Aug 06 '17 at 13:36
  • Don't confuse with `django-pipeline`. Python Social Auth has own pipeline. – Kaushal Aug 06 '17 at 13:42
  • @Kaushal I didn't define anything else in `settings.py` than what already appears in the question. The only pipeline defined is for `django-pipeline`, is it responsible for the error (i.e. is it picking the wrong pipeline... I've just added my pipeline to the question)? – Hakim Aug 06 '17 at 16:30

2 Answers2

3

Adding the pipeline below to settings.py seems to have fixed the problem (source):

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
    'social_core.pipeline.social_auth.associate_by_email',
)
Hakim
  • 2,479
  • 4
  • 33
  • 68
1

This error raises when trying to get a slice from a dict object. So, yes at the point of the last line of the traceback, pipelines is a dict object when it is supposed to be a sequence which default value is sociel_core.pipeline.DEFAULT_AUTH_PIPELINE unless your settings provides a PIPELINE object.

https://github.com/python-social-auth/social-core/blob/ccc50a5932b199a1a5209a08563c8997eb99391d/social_core/strategy.py#L99

https://github.com/python-social-auth/social-core/blob/ccc50a5932b199a1a5209a08563c8997eb99391d/social_core/pipeline/init.py#L1

Thus I suspect something probably in your settings module that messes this PIPELINE that should be a sequence (list, tuple, custom) and not a dict.

Hints: install ipython and play with python manage.py shell and inspect the followings.

>>> from social_core.strategy import BaseStrategy
>>> st = BaseStrategy()
>>> st.get_pipeline()
---> ???
>>> from django.conf import settings
>>> settings.PIPELINE
---> ???

Hope this helped

glenfant
  • 1,218
  • 8
  • 9
  • `st.get_pipeline()` throws this error: `NotImplementedError: Implement in subclass`. Should a pipeline be implemented with python-social-auth? – Hakim Aug 06 '17 at 21:18