This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Nostromos
about 9 years

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

0 votes

Permalink

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.

points
Submitted by Robert
about 9 years