2

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?

3
  • 4
    This is a programming problem and should be placed on Stack Overflow (There is nothing specific to the issue that you are having that says "open data")
    – user4293
    Aug 19, 2018 at 12:51
  • Do a print resp in your second bit of code just before data = resp.json(). There's no guarantee your 2 pieces of code are doing the same thing.
    – user3856
    Aug 19, 2018 at 19:09
  • @Jann is correct, ask on S.O. However, the error messages are staring you in the face, from the JSON. Read that and you should be able to figure it out. The input parameter ' city' is not known in this dataset.", u'error': u'parameter_not_foun d', etc Aug 29, 2018 at 13:13

1 Answer 1

1

I am afraid I am not familiar with python, however, I notice that the variables in the API are formatted differently than what the API is expecting - for example, you have "city" defined in your dict, however, the API is expecting "school.city".

I am not sure if it is possible to include dots like this for this specific implementation of the API call? Hope that is somewhat helpful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.