Python Social Auth - import error when using Google Authentication

I successfully followed this post over a month ago: http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/

When I created a new environment and recreated the steps, now I get an import error of no module named google_auth during template rendering.

It goes back to this line:

 <a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login</a> 

It seems that django is not looking for the correct template processing in a social application? Any ideas on why this is no longer working?

 #settings.py INSTALLED_APPS = (... , 'social.apps.django_app.default', ...) AUTHENTICATION_BACKENDS = ('social.backends.google.GoogleOAuth2', 'django.contrib.auth.backends.ModelBackend') TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'social.apps.django_app.context_processors.backends', 'social.apps.django_app.context_processors.login_redirect') #urls.py urlpatterns = patterns('', url('', include('social.apps.django_app.urls', namespace='social')), url('', include('django.contrib.auth.urls', namespace='auth')), url(r'^$', 'app.views.home', name='home'), ) 

EDIT: full trace below

 Environment: Request Method: GET Django Version: 1.7 Python Version: 2.7.8 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'charts', 'social.apps.django_app.default', 'djcelery', 'kombu.transport.django') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'social.apps.django_app.middleware.SocialAuthExceptionMiddleware', 'charts.middleware.SocialAuthExceptionMiddleware') Template error: In template charts/templates/base.html, error at line 69 No module named google_auth 59 : </ul> 60 : </li> 61 : <li> 62 : Hello, <strong>{{ user.get_full_name|default:user.username }}</strong>! 63 : </li> 64 : <li> 65 : <a href="{% url 'auth:logout' %}?next={{ request.path }}">Logout</a> 66 : </li> 67 : {% else %} 68 : <li> 69 : <a href=" {% url 'social:begin' 'google-oauth2' %} ?next={{ request.path }}">Login</a> 70 : </li> 71 : {% endif %} 72 : </ul> 73 : </nav> 74 : </head> 75 : <body> 76 : {% block content %} 77 : {% endblock %} 78 : <div id="footer"> 79 : <center> Traceback: File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/charts/views.py" in home 743. context_instance=context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/shortcuts.py" in render_to_response 23. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/loader.py" in render_to_string 174. return t.render(context_instance) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render 148. return self._render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in _render 142. return self.nodelist.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render 844. bit = self.render_node(node, context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node 80. return node.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/loader_tags.py" in render 126. return compiled_parent._render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in _render 142. return self.nodelist.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render 844. bit = self.render_node(node, context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node 80. return node.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/defaulttags.py" in render 312. return nodelist.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/base.py" in render 844. bit = self.render_node(node, context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/debug.py" in render_node 80. return node.render(context) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/template/defaulttags.py" in render 444. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse 517. app_list = resolver.app_dict[ns] File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in app_dict 329. self._populate() File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate 303. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args)) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback 231. self._callback = get_callable(self._callback_str) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/utils/lru_cache.py" in wrapper 101. result = user_function(*args, **kwds) File "//anaconda/envs/analytics/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable 101. not module_has_submodule(import_module(parentmod), submod)): File "//anaconda/envs/analytics/lib/python2.7/importlib/__init__.py" in import_module 37. __import__(name) Exception Type: ImportError at / Exception Value: No module named google_auth 
+5
source share
2 answers

If this is an option for you, I would suggest using django-allauth instead. I used both django-allauth and Python Social Auth, and itโ€™s much easier for me personally to work with django-allauth. Therefore, if you have a chance, try

+4
source

This is one difficult problem.

Error, the first line of the stack trace gives a hint: "Traceback: .... wrapped_callback ...." The social.apps.django_app.views.auth is called and wrapped in a psa decorator. This ultimately causes an error, but I think django.core.handlers.base.get_response hides the actual source of the exception. I think reraising makes stack traces incomplete at the moment.

An exception is probably found in from social.backends.utils.get_backend . But it is difficult to debug from a distance.

Can you comment on try-catch around the line response = wrapped_callback(request, *callback_args, **callback_kwargs) in the django.core.handlers.base file. What is the new stack trace when loading a page?

+2
source

Source: https://habr.com/ru/post/1205626/


All Articles