okfn / ckanclient-deprecated

DEPRECATED - please see https://github.com/ckan/ckanapi. [Python client library for CKAN]
http://pypi.python.org/pypi/ckanclient
25 stars 17 forks source link

problems with ~/.ckanclientrc #15

Closed timrdf closed 11 years ago

timrdf commented 11 years ago

Greetings,

I'm having some trouble getting ~/.ckanclientrc to work as https://github.com/okfn/ckanclient suggests.

While the following code works fine, it does not work when I remove the api_key argument -- even if I have specified the key in ~/.ckanclientrc (shown below).

How can I get the CkanClient to use the API key given in ~/.ckanclientrc?

Thanks for much! Tim Lebo

import ckanclient

# Instantiate the CKAN client.
ckan = ckanclient.CkanClient(base_location='http://datahub.io/api',
                            api_key='my-key') ## 403 error if this argument is removed (why isn't ~/.ckanclientrc taking over?).

# Get the details of a package.
ckan.package_entity_get('instance-hub-fiscal-years')
package_entity = ckan.last_message
package_entity['maintainer'] = 'TWC RPI'

print package_entity

ckan.package_entity_put(package_entity)
cat ~/.ckanclientrc
[index:http://datahub.io]
api_key = my-key
rufuspollock commented 11 years ago

@timrdf hi tim. I see @tobes has replied on list correctly indicated that there is a bug in the docs in that this is not actually supported. That said all the code for this is in the https://github.com/okfn/ckanclient/blob/master/ckanclient/datastore.py file and just needs to be moved across (I think that there had been a plan to do this but which somehow got stalled halfway).

timrdf commented 11 years ago

Thanks, @rgrp. As I said on list, I'll work around the issue as long as I can, and then re-raise it and/or fork the repo to add the older capability.

For my own reference, I discuss this issue #15 at https://github.com/timrdf/DataFAQs/wiki/DATAFAQS-environment-variables and https://github.com/timrdf/DataFAQs/wiki/CKAN, which is where I'll continue to elaborate my need for a ~/.ckanclientrc with different api keys for different ckan instances.

Regards, Tim

rufuspollock commented 11 years ago

Thanks. The fix here should be pretty easy (we just need to copy some of the code from datastore.py). The moment you ahve something we can review and merge.