I have the following code:
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
response = urlopen(url)
json_obj = load(response)
requiredAssets = '&requiredassets=image,text,audio'
url += requiredAssets
# uncomment 3 lines below to see JSON output to file
#f = open('output.json', 'w')
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 json_obj['list']['story']:
print "BYLINE: " + story['byline']+['name']['$text'] + "\n"
And receive the following error for line 24. This is a pop-up error, with no error reported in the terminal window.
Check the line where you print 'BYLINE:'. Don't forget a '\n' at the end of each line.
I am getting no other errors, and my code is producing the following output in the terminal:
TEASER: Ortho is part of the Miracle-Gro family. The company says it decided to phase out neonics from its home and garden products after reviewing possible threats posed to bees and other pollinators.
I appreciate any and all help!