-2

I am using python-social-auth API for authentication for facebook in my website. But I am getting an exception.

while using 'apps.pipeline.save_profile'

'cannot import name save_status_to_session'

I am using django-pipeline version 1.6.13

This code in pipelne.py

def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
    if kwargs.get('ajax') or user and user.email:
        return
    elif is_new and not details.get('email'):
    email = strategy.request_data().get('email')
    if email:
        details['email'] = email
    elif email is None:
        error = "Sorry, but your social network (Facebook or Google) 
                 needs to provide us your email address."
        return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + "?error=" + urllib.quote_plus(error))
    else:
        return redirect('require_email')


def save_profile(backend, details, response,  uid,user, *args, **kwargs):
    if backend.name == 'facebook':
      url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
      avatar = urlopen(url)
      profile = Profile.objects.filter(user_id=user.id)
      if profile.count()==0:
        profile = Profile(user_id=user.id)
      else:
        profile = Profile.objects.get(user_id=user.id)
        profile.profile_image.save(slugify(user.username + " social") + '.jpg', 
                        ContentFile(avatar.read()))              
        profile.save()

    elif backend.name == 'google-oauth2':
        if response.get('image') and response['image'].get('url'):
            url = response['image'].get('url')
            ext = url.split('.')[-1]
            profile = Profile.objects.filter(user_id=user.id)
            if profile.count()==0:
                profile = Profile(user_id=user.id)

            else:
              profile = Profile.objects.get(user_id=user.id)
              profile.profile_image.save(
              '{0}.{1}'.format(user.username, ext),
              ContentFile(urllib2.urlopen(url).read()),
              save=False
        )
              profile.save()

And settings

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.social_auth.associate_by_email',
'social.pipeline.user.get_username',
'polls.pipeline.require_email',
'social.pipeline.user.create_user',
'polls.pipeline.save_profile',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',

)

enter image description here

Ashok
  • 41
  • 1
  • 6

1 Answers1

1

It's very hard to give a correct answer based on the very limited amount of information you provided. I'll give it a try based on the screenshot you linked.

First, it seems there is an attempt to import save_status_to_session from social_core.pipeline.partial in file social/pipeline/partial.py. The import error is not surprising, as social_core.pipeline.partial does not define these this function (see https://github.com/python-social-auth/social-core/blob/master/social_core/pipeline/partial.py).

The file social/pipeline/partial.py seems to correspond to a module that is no longer maintained (see https://github.com/omab/python-social-auth/blob/master/social/pipeline/partial.py and the README at the root of the repository).

As you import that module in mysite/polls/pipeline.py, I suggest to replace your import from social.pipeline.partial import partial by from social_core.pipeline.partial import partial.

Guybrush
  • 2,680
  • 1
  • 10
  • 17