This forum is now read-only. Please use our new forums! Go to forums
I get "Way to go!" but code doesn't actually work.
The Python error statement is; Enter your zip code: 20001 URL: http://api.npr.org/stations?apiKey=API_KEY&format=json&zip=zip_code Traceback (most recent call last): File “python”, line 26, in
My code is ;
Line 26 in the error message above is “parse_station_json(json_obj)” Line 13 is “station[‘marketCity’][‘$text’] + “, “ +” However the error message refers to callLetters which is on line 12.
from urllib2 import urlopen
from json import load
key = "API_KEY"
def call_station_api(url):
response = urlopen(url)
j = load(response)
return j
def parse_station_json(json_obj):
for station in json_obj['station']:
print (station['callLetters']['$text']+ ": " +
station['marketCity']['$text'] + ", " +
station['state']['$text'])
def build_api_call(key):
url="http://api.npr.org/stations"
url+="?apiKey="+key
url+="&format=json"
zip_code = raw_input("Enter your zip code:")
url+="&zip=zip_code"
return url
url = build_api_call(key)
print "URL: "+ url
json_obj = call_station_api(url)
parse_station_json(json_obj)
Answer 52cc5833282ae3bb6b000a0c
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