Jump to content

How to refresh tokens with Python


 Share

Recommended Posts

I have tried to obtain a new access and refresh token with Python but I cant get it to work:

import http.client

connection = http.client.HTTPSConnection('oauth.accounting.sage.com', 443, timeout = 30)
headers = {"client_id":client_id_sage_value,
        "Content-Type":"application/x-www-form-urlencoded",
        "client_secret":client_secret_sage_value,
        "grant_type": "refresh_token",
        "refresh_token":refresh_token_value,
        "Accept":"application/json"}

# Send synchronously

connection.request('POST', '/token', None, headers)
try:
    response = connection.getresponse()
    content = response.read()
    # Success
    print('Response status ' + str(response.status))
except http.client.HTTPException as e:
    # Exception
    print('Exception during request')

 

I get a Response status 400 with the following content:

"

b'{"$severity":"error","$dataCode":"DataParsingError","$message":"The data you sent could not be processed.","$source":"Proxy"}'

 

Does anyone have any tips on how to obtain the refresh token with Python? It works in Postman with the user interface, also I can make GET requests with the some minor modifications to the code to obtain account information etc.

Link to comment
Share on other sites

Hi Richard, have you tried using a library such: as https://oauthlib.readthedocs.io/en/latest/index.html

Please let us know how this goes as I would like to review and possibly use python to access api also. 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...