This forum is now read-only. Please use our new forums! Go to forums
10/34 Can't pass exercise
The following code fails with the error: “Oops, try again. Great, you have requiredAssets Working. When you’re ready, specify text, audio, and images to pass this exercise.”
But, I have specified text,audio,images.
I must be missing something, but I’m unsure what it is.
from urllib2 import urlopen
from json import load, dumps
url = 'http://api.npr.org/query?apiKey='
key = 'API_KEY'
url = url + key
url += '&numResults=1&format=json&id=1007' #1007 is science
url += '&requiredAssets=text,audio,images'
response = urlopen(url)
json_obj = load(response)
# uncomment 3 lines below to see JSON output to file
# f = open('output.json', 'w')
# f.write(dumps(json_obj, indent=4))
# f.close()
for story in json_obj['list']['story']:
print "TITLE: " + story['title']['$text'] + "\n"
Answer 53f6a9fc282ae3f14900000f
2 votes
hi,
You need to # uncomment 3 lines, and add a code in last line. My code
f = open('output.json', 'w')
f.write(dumps(json_obj, indent=4))
f.close()
for story in json_obj['list']['story']:
print "TITLE: " + story['title']['$text'] + "\n"
&requiredAssets=audio,text,image
Answer 54cc6f5b95e37864b3000922
0 votes
from urllib2 import urlopen
from json import load, dumps
url = 'http://api.npr.org/query?apiKey='
key = 'API_KEY'
url = url + key
url += '&numResults=1&format=json&id=1007&requiredAssets=text,audio,image' #1007 is science
response = urlopen(url)
json_obj = load(response)
# uncomment 3 lines below to see JSON output to file
f = open('output.json', 'w')
f.write(dumps(json_obj, indent=4))
f.close()
for story in json_obj['list']['story']:
print "TITLE: " + story['title']['$text'] + "\n"
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
It helps!!! Thax a lot!!!