AttributeError:“模块”对象没有属性“ compare_digest”

时间:2019-07-31 13:39:04

标签: python django python-social-auth django-socialauth

我通过GoogleOauth2.0social-auth-app-django)配置了用户授权。

未创建 social_django / usersocialauth /应用程序中的条目。

在本地一切正常,但是服务器上发生错误。

选择要通过Google登录的帐户后,它将重定向到页面

complete / google-oauth2 / + GET参数

Traceback中,我得到以下信息:

跟踪

ERROR 2019-07-31 19:25:29,351 base 4745 139713585624832 Internal Server Error: /complete/google-oauth2/
Traceback (most recent call last):
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_django/utils.py", line 49, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_django/views.py", line 33, in complete
    *args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/actions.py", line 43, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/backends/base.py", line 40, in complete
    return self.auth_complete(*args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/utils.py", line 251, in wrapper
    return func(*args, **kwargs)
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/backends/oauth.py", line 388, in auth_complete
    state = self.validate_state()
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/backends/oauth.py", line 91, in validate_state
    elif not constant_time_compare(request_state, state):
  File "/home/deploy/.virtualenvs/finbee/lib/python2.7/site-packages/social_core/utils.py", line 227, in constant_time_compare
    return hmac.compare_digest(val1, val2)
AttributeError: 'module' object has no attribute 'compare_digest'

settings.py

MIDDLEWARE_CLASSES = (
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
)

TEMPLATES = [
    {
        'OPTIONS': {
            'context_processors': [
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.mail.mail_validation',
    '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',
)

INSTALLED_APPS = (
    #...
    'social_django',
)

AUTHENTICATION_BACKENDS = [
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
]

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY  =  '***********'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET  =  '****'

LOGIN_REDIRECT_URL = '/kredity/'

Google

https://example.com/complete/google-oauth2/


social-auth-app-django == 3.1.0

social-auth-core == 3.2.0

python == 2.7.6

0 个答案:

没有答案