Search code examples
pythonjsonapiqualtrics

Qualtrics API json error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


I have a Python GET API request that passes to json, and an error comes up on this line of my code:

data = json.loads(requestDownload.content)

Error is : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Object is created via:

requestDownloadUrl = baseUrl + fileId + '/file'
requestDownload = requests.request("GET", requestDownloadUrl, headers=headers, stream=True)

I took a look at the requestDownload response, which is [200], and the content is in bytes, which I assume passes through json.loads just fine (based on online documentation). However, it doesn't seem to work still. What should I do to troubleshoot this better?

Response and content


Solution

  • Since the content is in bytes, You'll need to decode them into a string before passing them to JSON.

    data = json.loads(requestDownload.content.decode("utf-8"))