08-17-2023 10:53 AM
I'm trying to exchange the authorization code for a user access token on Python.
But I got an "unsupported_grant_type" error from eBay sandbox API endpoint.
I think I sent the correct authorization code grant request.
class EBAYRestAPI: def __init__(self): self.auth_api = os.environ['EBAY_SANDBOX_AUTH_API'] self.client_id = os.environ['EBAY_CLIENT_ID'] self.client_secret = os.environ['EBAY_CLIENT_SECRET'] self.redirect_uri = os.environ['EBAY_REDIRECT_URI'] def _generate_request_headers(self): # credential_data = self.client_id + ':' + self.client_secret # cred_bytes = credential_data.encode('ascii') # base64_bytes = base64.b64encode(cred_bytes) # base64_msg = base64_bytes.decode('ascii') # print(base64_msg) data = bytes(self.client_id + ':' + self.client_secret, encoding='utf-8') b64_encoded_credential = base64.b64encode(data) print(b64_encoded_credential.decode(encoding='utf-8')) headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + b64_encoded_credential.decode(encoding='utf-8') } return headers def _generate_oauth_request_body(self, code): body = { 'grant_type': 'authorization_code', 'redirect_uri': self.redirect_uri, 'code':code } return body def exchange_code_for_access_token(self, code): headers = self._generate_request_headers() body = self._generate_oauth_request_body(code) response = urllib3.request('POST', self.auth_api, fields=body, headers=headers) content = response.json() print(content) return content
This is the response I received.
{ "error": "unsupported_grant_type", "error_description": "grant type in request is not supported by the authorization server" }
Just my Python code is running on my local.
Anyone can help me with the issue asap?
12-05-2023 09:18 AM
I'm having this same issue. Did you ever figure it out or can anyone help?
12-17-2023 12:15 AM
Did anyone solve this? Can they post the resolution? Thanks