[ckan-discuss] New Zealand CKAN Instance - API errors

David Read david.read at okfn.org
Tue Aug 17 18:54:45 BST 2010


Glen,

I've managed to track down the bug you came across creating packages
over the API. I've updated ckan.net with the fix, so please do have
another go and let me know how it goes.

About the bug: in creating the response header, some unicode text
slipped in. This doesn't cause a problem in WSGI, which our test-suite
runs in, but it does cause an exception in Apache. So the package got
created, but you got returned a badly formatted 500 error.

David

On 26 July 2010 21:37, Glen Barnes <glen at opengovt.org.nz> wrote:
>
> On 27/07/2010, at 2:17 AM, Rufus Pollock wrote:
>
> On 23 July 2010 11:11, Glen Barnes <glen at opengovt.org.nz> wrote:
>
> I've been working on getting the existing NZ catalogue migrated over to CKAN
> and have come across some issues. About 10 records were created via the API
> but now I can't seem to create any new ones. I've pasted a Gist with the
> connections I am making:
>
> http://gist.github.com/487236
>
>
> I basically do a get on the resource to see if it exists and if it doesn't
> then do a post to the api with the new package data (note I have deleted my
> key from the gist) for security reasons. I can do a get on an existing
> package "GET /api/2/rest/package/test"   and this returns the right data but
> posting won't work - It gives a 500 server error.
>
> If posting a *new* package I believe you need to post to the
> "register" api not a package API: /api/2/rest/package
>
> Posting to /api/2/rest/package/test implies an UPDATE not a CREATE.
> This could be made clearer in the docs I think. Also the error should
> not be a 500 but a 404 (not found) or perhaps 501 Not Implemented.
>
>
> Sorry - My text may not have been clear. If you look at the Gist you will
> see that I am posting to the register:
> POST /api/2/rest/package
> This is returning a 500 server error even when it does actually create the
> package sometimes. Friedrich was trying to debug it but I'm not sure where
> he got to. I can do a dump of my DB and send you my conversion code for you
> to test internally if needed.
>
> Any ideas of what could be wrong? Also when it 404's on the API it gives you
> back an HTML 404 page. Shouldn't it give you back a JSON formatted 404
> instead?
>
> What would you mean by a JSON-formatted 404? {'status': 404}. I
> believe the page does return the right status header (if not that is a
> bug!) and the html page is just a convenience.
>
> Yes - Any responses from the API should be JSON formatted so you can use the
> information inside the body in your app. Of course the headers say 404 which
> is what you should look at but you should be able to easily see the error
> message as well and you can include an other valid information
> {'status': 404, 'message': 'test package not found'}
> {'status': 503, 'message': 'You are not authorised to create this package.'}
> {'status': nnn, 'message': 'Validation Errors', 'errors':['name cannot be
> blank', 'license code must be an integer']}
> The reason being that screeds of html coming back in the response just makes
> it harder to debug and understand. Having the proper error codes/messages
> means that you can see why your package was not created.
> Hope this makes sense.
> _______________________________________________
> ckan-discuss mailing list
> ckan-discuss at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-discuss
>
>



More information about the ckan-discuss mailing list