Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django: type(social_user.extra_data) == unicode #898

Closed
codeleta opened this issue Apr 14, 2016 · 7 comments
Closed

Django: type(social_user.extra_data) == unicode #898

codeleta opened this issue Apr 14, 2016 · 7 comments

Comments

@codeleta
Copy link

Hello!

code:

social_user = get_object_or_none(
       self.request.user.social_auth.all(),
       provider='vk-oauth2'
)
strategy = load_strategy(self.request)
print type(social_user.extra_data)
social_user.refresh_token(strategy)

traceback:

in 0.2.16 version

<type 'unicode'>
Internal Server Error: /user-photos/load/vk-oauth2/
Traceback (most recent call last):
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 157, in get
    context = self.get_context_data(**kwargs)
  File "/home/user/papara/apps/user_photos/views.py", line 329, in get_context_data
    social_user.refresh_token(strategy)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/storage/base.py", line 49, in refresh_token
    token = self.extra_data.get('refresh_token') or \
AttributeError: 'unicode' object has no attribute 'get'

in 0.2.14 version

<type 'dict'>
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/django/views/generic/base.py", line 157, in get
    context = self.get_context_data(**kwargs)
  File "/home/user/papara/apps/user_photos/views.py", line 329, in get_context_data
    social_user.refresh_token(strategy)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/storage/base.py", line 54, in refresh_token
    response = backend.refresh_token(token, *args, **kwargs)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/backends/oauth.py", line 418, in refresh_token
    request = self.request(url, **request_args)
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/social/backends/base.py", line 225, in request
    response.raise_for_status()
  File "/home/user/.virtualenvs/papara/local/lib/python2.7/site-packages/requests/models.py", line 837, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://oauth.vk.com/access_token

psa send request vk.com: https://oauth.vk.com/access_token?client_id=<>&client_secret=<>&grant_type=refresh_token&refresh_token=<>
in 0.2.14 vk response: {"error":"invalid_grant","error_description":"Code is invalid or expired."}
vk get access_token docs
I think, "code" param miss

in 0.2.14 facebook and odnoklassniki refresh_token is OK.

@codeleta
Copy link
Author

extra_data fixed in Pull Request #897.
Error in vk.com refresh_token stay.

@troygrosfield
Copy link
Contributor

same issue here. Will be nice to get that PR merged in.

@youcandanch
Copy link
Contributor

@omab just a heads up that this is currently breaking a good amount of stuff using refresh token in mainline - any chance this could get a set of eyes and a version bump on pypi?

@youcandanch
Copy link
Contributor

@troygrosfield @Cotest it's been merged in and 0.2.18 is on PyPi now. Thanks, @omab!

@bcfurtado
Copy link

Still experiencing the same issue here though. Using version 0.2.18 with Django==1.6.11

@troygrosfield
Copy link
Contributor

This is still breaking for me as well with 0.2.18 and django==1.9.5.

clintonb referenced this issue in openedx-unsupported/edx-analytics-dashboard Apr 23, 2016
@clintonb
Copy link
Contributor

The default value of JSONField is incorrectly set to the string value '{}' instead of a dict, {}. See https://github.com/omab/python-social-auth/blob/master/social/apps/django_app/default/fields.py#L20.

Andygmb pushed a commit to tickettext/python-social-auth that referenced this issue Apr 25, 2016
@omab omab closed this as completed in #908 Apr 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants