S
S
Sergey Eremin2014-08-15 18:30:27
Django
Sergey Eremin, 2014-08-15 18:30:27

How to treat "WrongBackend" in django-social-auth?

Test application. Registered app in VK. I received an ID and a security key. For hosts, I redirected the domain registered in VK. Then I did it through PuCharm:
pip install django-social-auth
In settings.py I added 'social_auth' to INSTALLED_APPS:

INSTALLED_APPS = (
    # bla-bla-bla
    #...
    'social_auth',
)

Added there:
VK_APP_ID = '12345678'                       # мой ID для ВКонтакте
VK_API_SECRET = 'ir7HneLl1G8ugtIL1Z3z'      # мой защитный ключ для ВКонтакте

After I registered the backends in the same setting.py:
AUTHENTICATION_BACKENDS = (
    'social_auth.backends.contrib.vk.VKOAuth2Backend',                  # авторизация чекрез VKontakte
    'django.contrib.auth.backends.ModelBackend',                        # джанговский бэкэнд, иначе войти на сайт по связке пароль&логин будет невозможно.
    )

added a default user and allowed users to be created via social_auth:
SOCIAL_AUTH_DEFAULT_USERNAME = 'аnonymous'
SOCIAL_AUTH_CREATE_USERS = True

Listed the pipeline for sequential processing of the response from VKontakte:
SOCIAL_AUTH_PIPELINE = (
    'social_auth.backends.pipeline.social.social_auth_user',
    'social_auth.backends.pipeline.associate.associate_by_email',
    'social_auth.backends.pipeline.user.get_username',
    'social_auth.backends.pipeline.user.create_user',
    'social_auth.backends.pipeline.social.associate_user',
    'social_auth.backends.pipeline.social.load_extra_data',
    'social_auth.backends.pipeline.user.update_user_details',
)

By the way, it looks like the pipeline doesn't even get to work... Next, I add a pattern to urls.py:
url(r'', include('social_auth.urls')),
and don't forget "from django.conf.urls import include"... By the way, it's not very clear about r''. r'social/' to write with the same result...
After, of course, I execute:
manage.py syncdb
manage.py migrate social_auth

And in the template I write:
<a href="{% url 'socialauth_begin' 'vkontakte-oauth2' %}">Enter VK</a>

Look like that's it.
I'm launching.
I check that the template renders everything correctly and gets: But when you click this link, it falls out by mistake:
<a href="/login/vkontakte-oauth2/">Enter VK</a>
Exception Type:	WrongBackend
Exception Value:	Incorrect authentication service "vkontakte-oauth2"

traceback says:
C:\Program Files\Python\2.7\lib\site-packages\social_auth\decorators.py in wrapper
                raise WrongBackend(backend)

And it's not clear what to do. The feeling that somewhere is not connected somewhere, from social_auth ... something like "from social_auth import ????" must be added.
PS While I was struggling with the problem, I noticed that manager.py sometimes gets these messages:
Traceback (most recent call last):
  File "C:\Program Files\Python\2.7\lib\wsgiref\handlers.py", line 86, in run
    self.finish_response()
  File "C:\Program Files\Python\2.7\lib\wsgiref\handlers.py", line 128, in finish_response
    self.write(data)
  File "C:\Program Files\Python\2.7\lib\wsgiref\handlers.py", line 212, in write
    self.send_headers()
  File "C:\Program Files\Python\2.7\lib\wsgiref\handlers.py", line 270, in send_headers
    self.send_preamble()
  File "C:\Program Files\Python\2.7\lib\wsgiref\handlers.py", line 194, in send_preamble
    'Date: %s\r\n' % format_date_time(time.time())
  File "C:\Program Files\Python\2.7\lib\socket.py", line 324, in write
    self.flush()
  File "C:\Program Files\Python\2.7\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] ��������� �� ����� ����-
[15/Aug/2014 19:23:29] "GET /nav/124/31x40/?_=1408116205829 HTTP/1.1" 500 59
Traceback (most recent call last):
  File "C:\Program Files\Python\2.7\lib\SocketServer.py", line 595, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Program Files\Python\2.7\lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Program Files\Python\2.7\lib\site-packages\django\core\servers\basehttp.py", line 150, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "C:\Program Files\Python\2.7\lib\SocketServer.py", line 653, in __init__
    self.finish()
  File "C:\Program Files\Python\2.7\lib\SocketServer.py", line 712, in finish
    self.wfile.close()
  File "C:\Program Files\Python\2.7\lib\socket.py", line 279, in close
    self.flush()
  File "C:\Program Files\Python\2.7\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] ��������� �� ����� ����-
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 59045)
----------------------------------------

But sometimes they don't roll. Why this happens I don't understand. It seems to depend on whether you call via 127.0.0.1 or a domain alias from hosts. But maybe not...
PPS I'm running everything on port 8000. What difference does it make to VKontakte what ports I have ?!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
madeinnikolaev, 2016-11-12
@madeinnikolaev

If you have the latest version of django-social-auth, you need to use another provider for authorization.
Try to replace

<a href="{% url 'socialauth_begin' 'vkontakte-oauth2' %}">Enter VK</a>
on the
<a href="{% url 'socialauth_begin' 'vk-oauth' %}">Enter VK</a>
django-social-auth documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question