#-*- coding: utf-8 -*-
__author__ = 'LILI'
import requests
import json
import pprint
CKAN_URL = 'http://default.yourckan.com'
APIkey = 'API Key'
resourceID = 'resourceID'
def show_resource(APIkey, resourceID):
url = '{ckan}/api/action/resource_show'.format(
ckan=CKAN_URL)
headers = {}
headers['Content-Type'] = 'application/json'
headers['X-CKAN-API-Key'] = APIkey
headers['Authorization'] = APIkey
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0'
data={}
data['id'] = resourceID
data = json.dumps(data).encode('ascii')
r = requests.post(url, headers=headers,data=data)
return r.status_code, r.text
if __name__ == '__main__':
status_code, text = show_resource(APIkey, resourceID)
pprint.pprint(status_code)
pprint.pprint(text)
将代码最前面的CKAN_URL、APIkey、resourceID分别置换为自己的CKAN网址、自己的API key和resource ID。