[ckan-dev] Confused on response['success'] and HTTP status codes with empty results

Daniel Graziotin dgraziotin at task3.cc
Thu Mar 28 15:03:04 UTC 2013


> -----Original Message-----
> From: ckan-dev-bounces at lists.okfn.org [mailto:ckan-dev-
> 
> Hi Daniel,
> 
> Not directly related to your question, but I've been using ckan from within a
> plugin and most of my code looks like:
> 
>     try:
>         organization = get_action('organization_show')(context, {
>             'id':org['id'].lower()})
>         response = get_action('group_delete')(context, organization)
>     except NotFound:
>         pass
> 
> Is is possible for your new libckan api to look like this too?
> 

Hi Hian,

This is how a basic function looks like in libckan:

---
def name_action(client=client.Client(), id=''):
    resp = client.request(action='name_action', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
---

For the moment, it raises a generic CKANError. The Client object (basically it is a wrap around a urllib2 http request and json utils) raises CKANErrors, too.

After I cover the whole get actions, I will think about a clever way to subclass CKANError according to resp.error.

--Daniel Graziotin





More information about the ckan-dev mailing list