Created
December 11, 2018 09:44
-
-
Save howff/bcb445120016ef93210a4f782a362695 to your computer and use it in GitHub Desktop.
Test CKAN api key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This URL works when logged in as an admin: | |
http://172.16.92.142/api/3/action/package_search?include_private=True&include_drafts=True | |
This Python script does not work: | |
#!/usr/bin/env python2 | |
import urllib2 | |
import json | |
api_key = '1417c21c-7d04-48df-8f1b-8878edbd6153' | |
url='http://172.16.92.142/api/3/action/package_search?include_private=True&include_drafts=True' | |
request = urllib2.Request(url) | |
request.add_header('X-CKAN-API-Key', api_key) | |
request.add_header('Authorization', api_key) | |
response_dict = json.loads(urllib2.urlopen(request, '{}').read()) | |
print("Got %d results" % response_dict['result']['count']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
Testing this on my end I think I narrowed down the issue.
Try changing line 13 from
response_dict = json.loads(urllib2.urlopen(request, '{}').read())
toresponse_dict = json.loads(urllib2.urlopen(request).read())
removing the empty dict.Or, remove the query strings / params from your url and include them here like
response_dict = json.loads(urllib2.urlopen(request, '{"include_private":"true", "include_drafts":"true"}').read())