I have the following code and can not figure out why it won't run. I've tried it on Linux and FreeBSD with the same results:
This is the output I get when I run this code.
I was careful about syntax and really don't know why this won't run.
Code:
import json
from urllib import urlopen
url = "https://gdata.youtube.com/feeds/api/standardfeeds/top_rated?alt=json"
response = urlopen(url)
contents = response.read()
text = contents.decode('utf8')
data = json.loads(text)
for video in data['feed']['entry'][0:6]:
print(video['title']['$t'])
Code:
Traceback (most recent call last):
File "youtube.py", line 8, in <module>
data = json.loads(text)
File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded