Reputation: 1561
I am trying to fetch data from API from a tool called Paylocity.
I have managed to generate the access token and trying to connect to their API as below
client_id = client_id
client_secret = client_secret
company_id = company_id
prod_auth_url = 'https://apisandbox.paylocity.com/IdentityServer/connect/token'
body_params = urllib.parse.urlencode({'grant_type': 'client_credentials','scope':'WebLinkAPI'})
# Requests can use auth= for basic authentication
auth_response = requests.post(prod_auth_url,auth=(client_id, client_secret), data=urllib.parse.urlencode(body_params))
response = json.loads(auth_response.content)
api_call_headers = {'Authorization': 'Bearer ' + response['access']}
This however returns an error
TypeError: not a valid non-string sequence or mapping object
Upvotes: 1
Views: 297
Reputation: 1561
Figured out by changing the ** auth_response** variable as below
auth_response = requests.post(prod_auth_url,auth=(client_id, client_secret), data=body_params)
response = json.loads(auth_response.text)
Upvotes: 2
Reputation: 73
auth_response.content
gives you a byte string. Which likely causes the error. Use auth_response.text
.
Better even: You don't need json.loads()
here.
Just do:
response = auth_response.json()
Upvotes: 0