I used the following script to make an API call with credentials from this thread
import requests
username = 'johndoe'
password= 'zznAQOoWyj8uuAgq'
headersAuth = {
'accept': 'application/json',
'Content-length': ''
}
data = {'username': username,'password': password}
## Authentication request
response = requests.post('https://somedomain.test.com/token', headers=headersAuth, data=data, verify=True)
j = response.json()
print(j)
headersAPI = {
'accept': 'application/json',
'Content-length': '',
'Authorization': j['access_token']
}
# Making sample API call with authentication and API parameters data
response = requests.get('https://somedomain.test.com/api/Users/Year/2020/Workers', headers=headersAPI, verify=True)
api_response = response.json()
And when I print j
, I get None
. The output is:
j = response.json()
AttributeError: 'str' object has no attribute 'json'
How can I solve this error?