I am trying to generate a token from a REST API server with the following Python code:
import requests
import json
username = "username"
# put your password inside, exemple : password = "mypassword"
password = "password"
payload = {
'grant_type': 'password',
'username': username,
'password': password
}
r = requests.post("">sandbox.serversandbox.com/token",
headers={
"Content-type":"application/x-www-form-urlencoded",
"cache-control":"no-cache"
},
data=payload)
# this print command will return only the token
print(r.json()['access_token'])
# this print command will return the whole response
#print(r.text)
# this print command will return the status code (200 if ok)
# print(r.status_code)
But I'm getting the following error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
And the error points to the following:
---> 17 print(r.json()['access_token'])
Can someone let me know what could be the issue?