Richard Hallgren Posted June 8, 2021 Share Posted June 8, 2021 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 More sharing options...
test tester Posted June 9, 2021 Share Posted June 9, 2021 (edited) Not sure if this helps, but did you encode the token/post fields? Edited June 9, 2021 by test tester Link to comment Share on other sites More sharing options...
MOReg Posted June 14, 2021 Share Posted June 14, 2021 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now