Hi James,
Not sure where you're at with this issue but I have a few remarks that might help.
First of all, I think you've got it wrong on this line:
refresh_token = open('C:\Users\james.weston1\Desktop\access_token.json')
This returns a file pointer, not a string. Moreover, if the file contents is actually JSON, you would have to parse it to retrieve the token value.
So assuming the file contents looks like this:
{"refresh_token": "123456"}
Your script should look more like this:
import requests
import json
client_id = 123
client_secret = 123
url = "https://eu-apigw.central.arubanetworks.com/oauth2/token"
with open('C:\Users\james.weston1\Desktop\access_token.json') as f:
# Parse the file contents as json
access_data = json.load(f)
# Get the refresh token from the resulting dict
refresh_token = access_data['refresh_token']
qparams = {
"grant_type":"refresh_token",
"client_id": client_id,
"client_secret": client_secret,
"refresh_token": refresh_token
}
response = requests.request("POST", url, params=qparams)
print(response.text.encode('utf8'))
Then if you want to store the new refresh token into the same file, you would do something like this (in the same script):
(...)
response = requests.request("POST", url, params=qparams)
# extract the new refresh oken from the response
new_refresh_token = response.json()['resfresh_token']
# Update the access data you previously got from your json file
access_data['refresh_token'] = new_refresh_token
# Write the data back to your json file
with open('your/file.json', 'w') as f:
json.dump(access_data, f)
Hope it helps.