Jump to content

How to refresh tokens with Python


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,
        "grant_type": "refresh_token",

# Send synchronously

connection.request('POST', '/token', None, headers)
    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

  • Create New...