Skip to content

Yahoo backend handle key error #125

@roberto-robles

Description

@roberto-robles

I am getting the following error:

Environment:

Request Method: GET
Request URL: http://localhost/api/social/complete/yahoo-oauth/?oauth_token=qgf9qgm&oauth_verifier=xqmcyd

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'corsheaders',
'yahoo_app')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'corsheaders.middleware.CorsMiddleware',
'middleware.crossdomainxhr.XsSharing')

Traceback:
File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  2.     return view_func(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/apps/django_app/utils.py" in wrapper
  3.         return func(request, backend, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/apps/django_app/views.py" in complete
  4.                    redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/actions.py" in do_complete
  5.                              _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/strategies/base.py" in complete
  6.     return self.backend.auth_complete(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/oauth.py" in auth_complete
  7.     return self.do_auth(access_token, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/oauth.py" in do_auth
  8.     return self.strategy.authenticate(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/strategies/django_strategy.py" in authenticate
  9.     return authenticate(_args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/django/contrib/auth/init.py" in authenticate
  10.         user = backend.authenticate(**credentials)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in authenticate
  11.     return self.pipeline(pipeline, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in pipeline
  12.     out = self.run_pipeline(pipeline, pipeline_index, _args, *_kwargs)
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/base.py" in run_pipeline
  13.         result = func(_args, *_out) or {}
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/pipeline/social_auth.py" in social_details
  14. return {'details': strategy.backend.get_user_details(response)}
    
    File "/home/lladmin/hanu_api/shared/env/local/lib/python2.7/site-packages/social/backends/yahoo.py" in get_user_details
  15.         email = response.get('emails')[0]['handle']
    

Exception Type: KeyError at /social/complete/yahoo-oauth/
Exception Value: 'handle'

Above error comes because the response from yahoo contains a list with emails like the following:

response
{'access_token': {u'oauth_authorization_expires_in': u'_667',
u'oauth_expires_in': u'3600',
u'oauth_session_handle': u'_
_',
u'oauth_token': u'
__',
u'oauth_token_secret': u'
*_39b',
u'xoauth_yahoo_guid': u'
_6GM'},
u'created': u'2010-01-22T08:24:16Z',
u'emails': [{u'id': 1, u'type': u'HOME'},
{u'handle': u'
_
_ter@yahoo.com',
u'id': 2,
u'primary': True,
u'type': u'HOME'},
{u'id': 7, u'type': u'HOME'}],
u'familyName': u'
_****',
...}

I suggest iterate over the list of emails and check which element contains the handle key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions