This forum is now read-only. Please use our new forums! Go to forums
Keep Getting Message OOP's try again
Keep getting message OOP’s try again. I tried removing indents and retyping, but still get same message. Code shown below
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=audio,text,image’ #1007 is science #url += ‘&requireAssets= audio,text,image’ 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”
print “DATE: “ + story[‘storyDate’][‘$text’] + “\n”
print “TEASER: “ + story[‘teaser’][‘$text’] + “\n”
if ‘byline in story’:
print “BYLINE: “ + story[‘byline’][0][‘name’][‘$text’] + “\n”
if ‘show in story’:
print “PROGRAM: “ + story[‘show’][0][‘program’][‘$text’ ] + “\n”
print “NPR URL: “ + story[‘link’][0][‘$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