Python-social-auth登录(装饰器中的错误)

时间:2016-03-20 15:41:50

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

django social auth有问题。 我不知道该怎么办。当我点击ref时,我从社交网络获取所有信息(作为回应,如果我在函数login_vk中写了这个参数)。在请求中有

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

我写了这段代码

 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'

但我收到此错误

       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

如何解决此问题?


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 wich 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


模板

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

0 个答案:

没有答案