So I've been working on a page which displays a school's name, url, city, state, zip, and student size via College Scorecard API but I'm getting tons of errors instead. However, the program is able to read the JSON data just fine. For example, when I run this:
key = "key_string_here"
url_base = "https://api.data.gov/ed/collegescorecard/v1/schools/"
# Makes a get request to collegescorecard API
r = requests.get("https://api.data.gov/ed/collegescorecard/v1/schools/?
school.operating=1&2015.academics.program_available.assoc_or_bachelors=true&
2015.student.size__range=1..&school.degrees_awarded.predominant__range=1..3
&school.degrees_awarded.highest__range=2..4&id=240444&api_key=api_key_here")
school = r.json()
for item in school:
url = ("https://api.data.gov/ed/collegescorecard/v1/schools?"
"school.operating=1&2015.academics.program_available"
".assoc_or_bachelors=true&2015.student.size__range=1.."
"&school.degrees_awarded.predominant__range=1..3"
"&school.degrees_awarded.highest__range=2..4&id=240444&"
"api_key="+key+"&fields=school.name, school.school_url,"
"school.city,school.zip,school.state,2015.student.size")
req = urllib2.Request(url)
response = urllib2.urlopen(req)
response2 = response.read()
json_data=json.loads(response2)
print response2
I get the correct data:
{"metadata":{"total":1,"page":0,"per_page":20},"results":[{"school.n
ame":"University of Wisconsin-Madison","school.zip":"53706-1380","sc
hool.state":"WI","2015.student.size":29579,"school.school_url":"www.
wisc.edu","school.city":"Madison"}]}
However, when I try to parse the JSON data in a dictionary, like this:
params = dict(
school_name="University of Wisconsin-Madison",
school_url="www.wisc.edu",
city="Madison",
state="WI",
zip="53706-1380",
size="29579"
)
resp = requests.get(url=url, params=params)
data = resp.json()
print data
I get this in response:
{u'errors': [{u'input': u'city', u'message': u"The input parameter '
city' is not known in this dataset.", u'error': u'parameter_not_foun
d'}, {u'input': u'state', u'message': u"The input parameter 'state'
is not known in this dataset.", u'error': u'parameter_not_found'}, {
u'input': u'school_url', u'message': u"The input parameter 'school_u
rl' is not known in this dataset.", u'error': u'parameter_not_found'
}, {u'input': u'school_name', u'message': u"The input parameter 'sch
ool_name' is not known in this dataset.", u'error': u'parameter_not_
found'}, {u'input': u'size', u'message': u"The input parameter 'size
' is not known in this dataset.", u'error': u'parameter_not_found'},
{u'input': u'53706-1380', u'message': u"The provided zipcode, '5370
6-1380', is not valid.", u'parameter': u'zip', u'error': u'zipcode_e
rror'}]}
What am I doing wrong? How can I fix this problem?
print resp
in your second bit of code just beforedata = resp.json()
. There's no guarantee your 2 pieces of code are doing the same thing.The input parameter ' city' is not known in this dataset.", u'error': u'parameter_not_foun d'
, etc