Exception has occurred: JSONDecodeError App Store Connect Financial API using Python

  app-store-connect, python-3.x

I am trying to get financial data from my APP store connect account and am receiving a JSON error, see below:

import requests, time, json
from authlib.jose import jwt

EXPIRATION_TIME = int(round(time.time() + (20.0 * 60.0))) # 20 minutes timestamp
PATH_TO_KEY = "C:UsersjustiDesktopScript FilesApp Store Connectprivate_keyAuthKey_KEY.p8"
with open(PATH_TO_KEY, 'r') as f:
    PRIVATE_KEY = f.read()

header = {
    "alg": "ES256",
    "kid": KEY_ID,
    "typ": "JWT"

payload = {
    "iss": ISSUER_ID,
    "aud": "appstoreconnect-v1"

# Create the JWT
token = jwt.encode(header, payload, PRIVATE_KEY)

# URL Query Params
report_type = "filter[reportType]=FINANCE_DETAIL"
region_code = "filter[regionCode]=Z1"
report_date = "filter[reportDate]=2021-03"
vendor_number = "filter[vendorNumber]=VEND_###"

# API Request
JWT = 'Bearer ' + token.decode()
URL = 'https://api.appstoreconnect.apple.com/v1/financeReports?'+ report_type +'&' +region_code+ '&' + report_date + '&' +vendor_number
HEAD = {'Authorization': JWT}

r = requests.get(URL, params={'limit': 200}, headers=HEAD)

# Write the response in a pretty printed JSON file
with open('financial_report.json', 'w') as out:
    out.write(json.dumps(r.json(), indent=4))

I am getting a 200 response from my r object but when I go to dump the JSON data, here is my error:

Has any one seen this before?

Is the response not a JSON object (which would be strange)?

Thank you in advance!

Source: Python-3x Questions