I need to call this api "<https://api.descope.com/...
# ask-a-descoper
e
I need to call this api "https://api.descope.com/oauth2/v1/token" from python sdk descope client. Which version should I use? now I am using descope==1.7.9 the commands does not work jwt_resp = client.oauth.exchange(code) jwt_resp = client.oauth.exchange_token(code)
a
@EmilioDS what error are you getting?
Copy code
jwt_response = descope_client.oauth.exchange_token(code)
should give you a refresh and access token
e
descope.exceptions.AuthException: {'status_code': 401, 'error_type': 'server error', 'error_message': '{"errorCode":"E061301","errorDescription":"Failed to exchange token","errorMessage":"Failed exchanging sso token","message":"Failed exchanging sso token"}'}
a
the error code means your auth code obtained from the SSO provider is either invalid or is missing can you check if the code variable is populated before running this command?
e
yes I can call successful fetching the url using authcode but from the sdk it does not work if I call it like this DESCOPE_TOKEN_URL = "https://api.descope.com/oauth2/v1/token" form = { "grant_type": "authorization_code", "code": code, "redirect_uri": redirect_uri, "client_id": DESCOPE_PROJECT_ID, "code_verifier": code_verifier, } resp = requests.post( DESCOPE_TOKEN_URL, headers={"Content-Type": "application/x-www-form-urlencoded"}, data=form, timeout=10, ) it works but I want to call it from sdk
a
I see Can you confirm for me that our following the steps in this doc? Also please try running this command instead -
resp = descope_client.oauth.exchange_token(code=code)