2

Using the data.gov CKAN api, this search via the web GUI returns 566 results: children

However, post requests via the CKAN API returns 10 results despite the row parameter being set and, incidentally, it appears that no matter the search query that the results are the same.

import json, requests
url = 'http://catalog.data.gov/api/3/action/package_search'
headers = {'Content-type': 'application/json'}
q1 = {'q':'abcdefghijklmnopq', 'rows':600}
q2 = {'q':'children', 'rows':600}

queries = [q1, q2]
responses = []

for q in queries:
    r = requests.post(url, data=json.dumps(q), headers=headers)
    r = r.json()
    print(len(r['result']['results']))
    responses.append(r)

print(responses[0] == responses[1])

Given the example above code what modifications allow the CKAN api to reflect the web GUI search results.

note: this question has been posted as an data.gov issue

note: the solution at data.gov action api parameters seem to be ignored appears to no longer return just 2 results

  • 1
    I responded in the data.gov github issue, but just to copy it over here, it looks like the problem is specific to using a JSON object to construct the request. This looks like a bug that needs to be fixed, but in the meantime, the request should work fine using traditional application/x-www-form-urlencoded parameters – Philip Ashlock Dec 21 '15 at 23:05
  • 1
    Thanks @PhilipAshlock. If you make your comment an answer I can accept it. – Kwame Jan 2 '16 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.