I have an API that has been set up on the server side and the unit side, I have the below code in python to communicate with the API. I am now writing this for the Arduino IDE.
This code successfully communicates with the API to get the token.
How is this code sending a JSON string ‘auth_info’ while the header reads x-www-form-urlencoded.
Even a half explanation of the following would be really appreciated.
PYTHON CODE STARTS
def get_user_auth_token():
global token
purl = host+'/api/oauth/token'
head = {'Content-Type' : 'application/x-www-form-urlencoded'}
auth_info = {'client_id' : "unit:"+api_params.id,
'grant_type' : 'client_credentials',
'client_secret' : api_params.secret,
'scope' : 'unit',
}
# print(purl)
# print(auth_info)
# print(head)
r = requests.post(purl, auth_info, head)
response=json.loads(r.text)
token = response['access_token']
PYTHON CODE ENDS