I am a beginner at python. I am trying to use json.loads() in my code to iterate over a json object returned from an API.
The following is the error I am getting:
Traceback (most recent call last):
File "/Users/Saket/Downloads/Telegram Desktop/update_trbble (2).py", line 209, in <module>
today_trbbles=json.loads(open_discovery_api)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 36: unexpected end of data
logout
I have checked out a few posts and tried to use .encode('utf-8') and also convert to unicode by using the unicode() method. These also are not working.
sample data:
status: 0,
message: "success",
results: {
totalTime: "3 ms",
queryTime: "0 ms",
status: 0,
cursor: "AoJ/spqIs9ICPwU4YzcyNWFlZi1hNjM1LTRiNzEtYjM1Ni02MWQ2MWFlMGQwZWU=",
numFound: 523,
size: 30,
songss: [
{
albumArt: "https://i.scdn.co/image/233728c2073337d67309fd205c6cc028e831d857",
artist: "Arty, Nadia Ali & BT",
docSource: [
"CACHE"
],
commentCount: 0,
createdBy: "wiredmau5",
createdTime: "Fri Jan 22 15:07:45 UTC 2016",
createdUTS: 1453475265411,
createdUserId: "ae186330-5fa5-469c-b1cc-8f3d3b61e538",
downVoteCount: 0,
favouriteCount: 0,
flag1Count: 0,
falg2Count: 0,
flag3Count: 0,
flag4Count: 0,
flag5Count: 0,
flag6Count: 0,
genre: [
"Trance"
],
genrePriority: 0,
hour: 0,
language: "english",
languagePriority: 0,
likeCount: 0,
minute: 0,
modifiedTime: {
time: 1453475748201,
minutes: 15,
seconds: 48,
hours: 15,
month: 0,
year: 116,
timezoneOffset: 0,
day: 5,
date: 22
},