[Python] Python-social-auth login (error in decorator)

Discussão em 'Python' iniciado por Stack, Junho 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem with Django social auth. I don't know what to do. When I click on ref I get all information from social network (in response if I wrote this argument in function login_vk). In request there is

    <QueryDict: {u'state': [u'5v7znP0lBNmp33V2TCOSshU4mQe4MlDn'], u'code': [u'a6acfde533fbd83437'], u'redirect_state': [u'5v7znP0lBNmp12V2TCOSshU4mQe4MlDn']}>


    I wrote this code:

    from social.apps.django_app.utils import psa
    @psa('social:complete')
    def login_vk(request, backend):
    token = request.GET.get('access_token')
    user = request.backend.do_auth(request.GET.get('access_token'))
    if user:
    login(request, user)
    return 'OK'
    else:
    return 'ERROR'


    but I get this error


    Exception Value:
    'QueryDict' object has no attribute 'session' Exception Location: /usr/local/lib/python2.7/dist-packages/social/strategies/django_strategy.py in init, line 30
    ​

    How can I resolve this problem?

    settings.py

    INSTALLED_APPS = ('social.apps.django_app.default',)
    SOCIAL_AUTH_VK_OAUTH2_KEY = 'xxx'
    SOCIAL_AUTH_VK_OAUTH2_SECRET = 'xxx'
    SOCIAL_AUTH_LOGIN_URL = '/app/oauth2login' # URL for callback
    #SOCIAL_AUTH_USER_MODEL = 'polls.models.MyUser' # custom user
    SOCIAL_AUTH_UID_LENGTH = 223
    SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
    SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'
    SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'polls.views.login_vk', # method which works with social network
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    )

    # 'social.apps.django_app.default', into INSTALLED_APPS

    AUTHENTICATION_BACKENDS = (
    'social.backends.vk.VKOAuth2', # and other
    # setups and becks https://python-social-auth.readthedocs.org/en/latest/backends/index.html
    'django.contrib.auth.backends.ModelBackend',
    )


    urls.py

    url(r'^app/', include('social.apps.django_app.urls', namespace='social')),
    url(r'^app/oauth2login$', views.oauth2login_view), # views for auth


    template

    <a href="http://nochgames.ru/app/login/vk-oauth2/" target="blank">Login with VK</a>

    Continue reading...

Compartilhe esta Página