[ckan-discuss] Uploading resources using CkanClient
Sean Hammond
sean.hammond at okfn.org
Mon Sep 3 10:35:44 BST 2012
> I'm struggling to upload files using CkanClient.
>
> Here is my code
>
> import ckanclient
> import sys
>
>
> key = "...."
>
> ckan = ckanclient.CkanClient(api_key=key,
> base_location="http://data.codingfordemocracy.org/api")
>
> f = sys.argv[1]
> ckan.add_package_resource("census-2001", f, resource_type="data")
>
>
> I get the following error:
>
> Traceback (most recent call last):
> File "upload.py", line 18, in <module>
> ckan.add_package_resource("census-2001", f, resource_type="data")
> File "/usr/local/lib/python2.7/dist-packages/ckanclient/__init__.py",
> line 724, in add_package_resource
> return self.package_entity_put(p)
> File "/usr/local/lib/python2.7/dist-packages/ckanclient/__init__.py",
> line 299, in package_entity_put
> self.open_url(url, data, headers, method='PUT')
> File "/usr/local/lib/python2.7/dist-packages/ckanclient/__init__.py",
> line 231, in open_url
> raise CkanApiConflictError(self.last_status)
> ckanclient.CkanApiConflictError: 409
>
> I also see this suspicious message in my apache logs:
>
> IOError: failed to write data but it doesn't give me any context.
>
> I've check that www-data has write access to my filestore directory as
> well as pretty much the entire ckan folder.
>
> Any suggestions on where else to look?
Does file uploading work via the web interface?
With a 409 Conflict, one possibility is that the file you're trying to
upload has already been uploaded to the filestore. Try uploading a
different file.
Personally I think ckanclient is quite hard to use, one reason being
that it gives obfuscated error messages like the one you're getting, and
I think it's better to post directly to CKAN's v3 API using e.g.
Python's standard http module, as you get a much clearer idea of what's
going on and particularly what's going wrong.
But I think uploading a file is possibly the one thing that would be
quite complicated to do that way.
I believe someone is working on simplified file uploading for CKAN...
More information about the ckan-discuss
mailing list