Python使用Ckan API查找并展示特定的resource内容
2016-07-29 11:29
465 查看
#-*- 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。
相关文章推荐
- Python使用BeautifulSoup提取特定HTML标签内容
- Python---对html文件内容进行搜索取出特定URL地址字符串,保存成列表,并使用每个url下载图片,并保存到硬盘上,使用bs4,beautifulsoup模块
- Python使用Ckan API创建并上传resource
- 使用python查找目录下特定后缀名的文件
- Python----使用正则re查找文本中特定中文字符串
- Python---对html文件内容进行搜索取出特定URL地址字符串,保存成列表,并使用每个url下载图片,并保存到硬盘上,使用正则re
- 如何使用FindControl查找内容页上的某个控件?
- 使用权限标签控制View层展示的内容
- 使用权限标签控制View层展示的内容
- 使用权限标签控制View层展示的内容
- 使用HttpHandler解析并展示PDF文档内容(转载)
- 使用权限标签控制View层展示的内容
- 使用权限标签控制View层展示的内容
- 如何使用FindControl查找内容页上的某个控件
- 使用权限标签控制View层展示的内容
- 使用HttpHandler解析并展示PDF文档内容
- 使用权限标签控制View层展示的内容
- 使用权限标签控制View层展示的内容
- 使用批处理删除HOSTS中特定内容的行
- 使用权限标签控制View层展示的内容