Skip to content Skip to sidebar Skip to footer

Why Am I Getting Decoder Errors When Turning My Json Array Into A Python List Using Json.loads?

Below is the error code I received on my Terminal call of 'python lastYearArray.py'. (I'm on a MacBook Pro running OSX 10.9.5, editing my Python program in jEdit). According to thi

Solution 1:

requests.get returns a Response object. That object is not a string object, so you cannot pass it to json.loads.

You have to get the response object’s using response.text, and pass that to json.loads:

lastYearArrayResponse = requests.get('…')
data = json.loads(lastYearArrayResponse.text)

Alternatively, you can also use the response.json() method to get the parsed response since requests already comes with built-in support for JSON responses:

lastYearArrayResponse = requests.get('…')
data = lastYearArrayResponse.json()

Solution 2:

You forget to add .text at the end of line lastYearArray = to get the HTML source of the webpage.

Also, I think the last line is not correct...

Post a Comment for "Why Am I Getting Decoder Errors When Turning My Json Array Into A Python List Using Json.loads?"