[ckan-dev] Problem making HTTP request to create a package using CKAN API

Alex Gartner alexandru.gartner+ckan at gmail.com
Tue Dec 20 19:16:04 UTC 2016


Hi,

as I see there's already a dataset with the name "my_dataset_name" on
demo.ckan.org.

I guess that's why you get the error.

Alex

On Dec 20, 2016 10:30 PM, "David" <davisoski at gmail.com> wrote:

> Hi.
>
> I'm trying to create a package test in *demo.ckan.org
> <http://demo.ckan.org>* using api with the python example in:
>
> http://docs.ckan.org/en/latest/api/index.html#example-
> importing-datasets-with-the-ckan-api
>
>
> This is the code taken from the web example, just changed API KEY
>
> # Put the details of the dataset we're going to create into a dict.
> dataset_dict = {
>     'name': 'my_dataset_name',
>     'notes': 'A long description of my dataset',
> }
>
> # Use the json module to dump the dictionary to a string for posting.
> data_string = urllib.quote(json.dumps(dataset_dict))
>
> # We'll use the package_create function to create a new dataset.
> request = urllib2.Request(
>     'http://demo.ckan.org/api/3/action/package_create')
>
> # Creating a dataset requires an authorization header.
> # Replace *** with your API key, from your user account on the CKAN site
> # that you're creating the dataset on.
> request.add_header('Authorization', '97caad21-8632-4372-98fe-
> a24cdcaa90dc')
>
> # Make the HTTP request.
> response = urllib2.urlopen(request, data_string)
> assert response.code == 200
>
> # Use the json module to load CKAN's response into a dictionary.
> response_dict = json.loads(response.read())
> assert response_dict['success'] is True
>
> # package_create returns the created package as its result.
> created_package = response_dict['result']
> pprint.pprint(created_package)
>
> I'm getting error:
>
> Traceback (most recent call last):
>   File "C:/create_dataset_ckan_api_demo_org.py", line 40, in <module>
>     response = urllib2.urlopen(request, data_string)
>   File "C:\Python27\lib\urllib2.py", line 154, in urlopen
>     return opener.open(url, data, timeout)
>   File "C:\Python27\lib\urllib2.py", line 437, in open
>     response = meth(req, response)
>   File "C:\Python27\lib\urllib2.py", line 550, in http_response
>     'http', request, response, code, msg, hdrs)
>   File "C:\Python27\lib\urllib2.py", line 475, in error
>     return self._call_chain(*args)
>   File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
>     result = func(*args)
>   File "C:\Python27\lib\urllib2.py", line 558, in* http_error_default*
> *    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)*
> HTTPError: HTTP Error 409: Conflict
>
>
> BUT
>
> the code to get activities from a user works great, so I suppose is not a
> key problem
>
>
> request = urllib2.Request('http://demo.ckan.org/api/3/action/
> dashboard_activity_list')
> request.add_header('Authorization', '97caad21-8632-4372-98fe-
> a24cdcaa90dc')
> response_dict = json.loads(urllib2.urlopen(request, '{}').read())
>
>
> assert response_dict['success'] is True
> result = response_dict['result']
> pprint.pprint(result)
>
>
> Any help?
>
> Thanks
>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20161220/f93d5078/attachment-0003.html>


More information about the ckan-dev mailing list