HTTP Error 403: Forbidden on 8.26


#1

Hi! I'm receiving a 403 error when attempting to pass the url in the lesson to urlopen:

from urllib2 import urlopen
from json import load

key = "API_KEY"
url = "http://www.npr.org/2012/05/08/152248901/fresh-air-remembers-author-maurice-sendak?apiKey="
url = url + key
url += "&format=jason&id=152248901"

response = urlopen(url) #will open if I copy/paste url in browser so i know the url is correct.
j = load(response)

for paragraph in j["paragraph"]:
print paragraph["$text"] + "\n"

Any help is appreciated!


#2

It wants you to put this code:

from urllib2 import urlopen
from json import load
url = "http://api.npr.org/query?apiKey="
key = "API_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']

The box in the comer should ask you this: Which NPR ID do you want to query? and you should type this number: 152285927. I hope this helped you!

~Fiona~