This forum is now read-only. Please use our new forums! Go to forums
Traceback error on default code
I keep getting this error:
Traceback (most recent call last):
File "python", line 19, in <module>
KeyError: 'list'
I was having similar problems with the previous exercise, so I skipped ahead, using Codecademy’s default/provided code and it doesn’t seem to work either!
Here is Codecademy’s code that doesn’t pass:
from urllib2 import urlopen
from json import load
key = "API_KEY"
url = "http://api.npr.org/query?apiKey=" + key
url += key
url += '&numResults=3' + '&format=json' + '&id='
npr_id = raw_input("Which NPR ID do you want to query?")
url += npr_id
print url
response = urlopen(url)
json_obj = load(response)
for story in json_obj['list']['story']:
print story['title']['$text']
I’m guessing this probably isn’t the most important thing you guys are working on, but come on, there are questions over a year old in the forums that haven’t been dealt with, either by users or by Codecademy.
Answer 54e7afc79113cb0ab8000573
You are getting the error… not because Codecademy has an error, but because NPR returned an error to you, which is why json_obj['list']
didn’t exist in its response.
url = "http://api.npr.org/query?apiKey=" + key
url += key
You’ve added key twice… and NPR is failing your query. If you tried print json_obj
before the for loop, you’d see their error message.
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