版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/coffee_cream/article/details/52062990
#-*- coding: utf-8 -*-
__author__ = 'LILI'
import urllib2
import urllib
import json
import pprint
CKAN_URL = 'http://default.yourckan.com'
def groupList():
# Use the json module to dump a dictionary to a string for posting.
data_string = urllib.quote(json.dumps({'id': 'data-explorer'}))
# Make the HTTP request.
url = '{ckan}/api/3/action/group_list'.format(ckan=CKAN_URL)
response = urllib2.urlopen(url,data_string)
assert response.code == 200
# Use the json module to load CKAN's response into a dictionary.
response_dict = json.loads(response.read())
# Check the contents of the response.
assert response_dict['success'] is True
result = response_dict['result']
return result
if __name__ == '__main__':
result = groupList()
pprint.pprint(result)
将代码最前面的CKAN_URL置换为自己的CKAN网址。