Community Discussion
JSON Error when calling API in Python
7 months ago by Miguel
Hey all,
New to this API and testing it out, but I'm having some issues returning some fairly basic data from my account using Python and reading it via a json command. Here's a very simple code and the error I'm getting:
account_id = account_response.json()['results'][0]['id']
account_url = url + "/api/1.0/api/1.0/{account_id}/campaigns/base".format(account_id = account_id)
campaigns_response = requests.get(account_url, headers=headers)
campaigns_response.json()
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I'm not sure why this is happening, as when I run campaigns_response.ok, I get a 'True' return. Also, when I run a simple call to get my account details:
headers = {'Authorization': f'Bearer {access_token}'}
account_response = requests.get(url + '/backstage/api/1.0/users/current/allowed-accounts/', headers=headers)
This runs fine.
Any help/insight would be much appreciated.
Thanks!