python - 在 Django 中使用 python-social-auth 重定向回网站时不可散列的类型

标签 python django facebook django-socialauth

我正在尝试使用 Social-auth-app-django 向网站添加社交媒体身份验证.

所以我为最流行的社交媒体网站(Facebook、Twitter、Google+)创建了不同的应用程序,并在那里设置了回调 url。

但是当我从 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'

下面是我如何配置 social_django 的总结:

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

之后,显然我已经迁移了数据库以创建新表。

请在下面找到 Djangosocial_django 的版本:

  • Django:1.10.5
  • social_django:1.2.0

关于使用的管道,我使用的是 django-pipeline 但它只是用于将 SASS 文件编译为 CSS

什么可能导致此错误?

最佳答案

将下面的管道添加到 settings.py 似乎已经解决了问题(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',
)

关于python - 在 Django 中使用 python-social-auth 重定向回网站时不可散列的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45379174/

相关文章:

python - Django 分页不起作用

python - 为什么 Python 的 `requests` 拒绝我的浏览器接受的 SSL 证书

python - Django UpdateView 的内联表单集

javascript - 使用 Facebook 帐户 (Meteor) 登录不起作用

facebook - 收集 Facebook 直播公开数据

python - 如何展平解析树并存储在字符串中以进行进一步的字符串操作python nltk

python - 在 response().read() 中搜索特定信息

python - 异常值 : context must be a dict rather than WSGIRequest

Django 管道缓存破坏不更新缓存文件/哈希

jquery - Facebook 喜欢按钮和颜色框