Uploading VTT Captions with Python Requests results in 10004 Decoding Error

I’m trying to upload captions to videos using the requests library in python3 using the following function.

def upload_captions(CF_VIDEO_URL, caption_file, caption_language):
    # Uploads and associates caption_file with CF_VIDEO_URL
    files = {
        'file': open(caption_file, 'rb')
    }

    r = requests.put(f"{config.CF_API_ENDPOINT}/accounts/{config.CF_ACCOUNT_ID}/stream/{CF_VIDEO_URL}/captions/{caption_language}",
                      headers=config.CF_HEADERS, files=files)
    parsed = json.loads(r.text)

I’m logging the response in my dev environment, where I get am HTTP 400 and the following json returned:

{'result': None, 'success': False, 'errors': [{'code': 10004, 'message': 'Decoding Error'}], 'messages': None}

I’ve confirmed that the .vtt file I’m using is valid by associating it with the test video manually, and I assume that the upload URL is well-formed, given that it’s the same basic URL that I’m successfully using to upload videos with the requests library.

Alright, so it looks like the issue, ultimately, was with the headers being passed in. Specifically, this snippet was reusing the same headers that had been successfully used to upload videos to Stream, which included Content-type: application/json along with the authorization headers. Removing all headers other than the authorization headers resolved this issue.