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

banner
Close banner
0 points
Submitted by Fahad Al Rabbani
almost 11 years

The code looks fine but does not run???

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
url += '&requiredAssets=audio,text,image'
response = urlopen(url)
json_obj = load(response)


for story in json_obj['list']['story']:
print "TITLE: " + story['title']['$text'] + "\n"

I get a error with this message below: Did you create a query string parameter for requiredAssets?

Even though I have created requiredAssets with the appropirate atrributes, it does not run.

Need help

Answer 51d1939f631fe9b11a016b57

-4 votes

Permalink

Put the ‘A’ in ‘requiredAssets’ (sic) in lowercase. Your final string should be:

 url += 'requiredassets=audio,text,image'
points
Submitted by Utsav Popat
almost 11 years

1 comments

Hemanth Kondapalli over 8 years

instead of having required assets only in the url definiton. make it an independent variable and concatenate to the url string after.