Error with BYLINE in Lesson 11 "Print Date, Teaser, Byline"


#1

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')
#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 json_obj['list']['story']:
    print "BYLINE: " + story['byline'][0]+['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.

None

I appreciate any and all help!


#2

Link to exercise, please. Thank you.


#3

https://www.codecademy.com/en/courses/python-intermediate-en-NwwHi/1/3?curriculum_id=50ecb8cb058fd2ebda00003b


#4

Try,

    story['byline'][0]['name']['$text']

as in,

    print "BYLINE: " + story['byline'][0]['name']['$text'] + "\n"