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

ValueError: Unsupported token type: User Access Token #403

Closed
thiras opened this issue Mar 31, 2020 · 5 comments
Closed

ValueError: Unsupported token type: User Access Token #403

thiras opened this issue Mar 31, 2020 · 5 comments

Comments

@thiras
Copy link

thiras commented Mar 31, 2020

Hello. I've got some error after successfully obtain a token from eBay.

As you can see at its documentation eBay returns "token_type": "User Access Token"

After getting the token without having a problem, when I try to request anything from its endpoint I get;

Traceback (most recent call last):
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/bin/rods", line 11, in <module>
    load_entry_point('rpi-order-data-sync', 'console_scripts', 'rods')()
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/thiras/HDD/freelancer/contentassasin/rpi-order-data-sync/rpi_order_data_sync/main.py", line 132, in sync_ebay_orders
    orders = ebay.get(
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 477, in request
    url, headers, data = self._client.add_token(
  File "/home/thiras/.local/share/virtualenvs/rpi-order-data-sync-tA0i1rrc/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 192, in add_token
    raise ValueError("Unsupported token type: %s" % self.token_type)
ValueError: Unsupported token type: User Access Token 
@thiras
Copy link
Author

thiras commented Mar 31, 2020

I've changed token type with "Bearer" manually and it worked.

@thiras thiras closed this as completed Mar 31, 2020
@sambragg
Copy link

sambragg commented May 5, 2020

I'm having this same issue with another provider. @thiras, if you don't mind - please could you tell me how you changed the token_type manually?

@thiras
Copy link
Author

thiras commented May 5, 2020

@sambragg sure. Check my solution here; https://stackoverflow.com/a/61001852/4132845

Also check register_compliance_hook at the official docs.

@sambragg
Copy link

sambragg commented May 6, 2020

This is great, thank you so much @thiras

@sambragg
Copy link

@thiras I couldn't get your solution to work. Incase anyone else has this issue, what I ended up doing was the following:

import json
from oauthlib.common import to_unicode

self.oauth.register_compliance_hook('access_token_response', self.non_compliant_token)
self.oauth.register_compliance_hook('refresh_token_response', self.non_compliant_token)

def non_compliant_token(self, response):
        token = json.loads(response.text)
        token["token_type"] = "Bearer"
        fixed_token = json.dumps(token)
        response._content = to_unicode(fixed_token).encode("utf-8")
        return response

This avoids having to create a fake class etc.

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

2 participants