Posts

Showing posts with the label ckan

Creating a CKAN package/dataset with resources using ckanapi and Python

CKAN provides the ckanapi package for accessing the CKAN API via Python or the command line. I can use it to download metadata, create resources, etc. But I can't create a package and upload resources to it in a single API call. (A package is also referred to as a dataset.) Internally, ckanapi scans all keys moving any file-like parameters into a separate dict , which it passes to the requests.session.post(files=..) parameter. This is the closest I can get but CKAN returns an HTTP 500 error (copied from this guide to requests ): I've also tried resources=open('path/file') , files=open('file') , shorter or longer tuples, but get the same 500 error. The requests documentation says: I can't pass ckanapi resources={'filename': open('file')} as ckanapi doesn't detect the file, attempts to pass it to requests as a normal parameter, and fails ("BufferedReader is not JSON serializable" as it attempts to make the file a POST par...