Create CKAN dataset using CKAN API and Python Requests library

后端 未结 2 1503
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 03:25

I am using CKAN version 2.2 and am trying to automate dataset creation and resource upload. I seem to be unable to create a dataset using the python requests libra

2条回答
  •  失恋的感觉
    2021-01-03 03:41

    The data you send must be JSON encoded.

    From the documentation (the page you linked to):

    To call the CKAN API, post a JSON dictionary in an HTTP POST request to one of CKAN’s API URLs.

    In the urllib example this is performed by the following line of code:

    data_string = urllib.quote(json.dumps(dataset_dict))
    

    I think (though you should check) that the requests library will do the quoting for you - so you just need to convert your dict to JSON. Something like this should work:

    r = requests.post(d_url, data=json.dumps(dataset_dict), headers=auth)
    

提交回复
热议问题