0

Is there a way to get errors or debug when update my resources to CKAN using API.??

After create it using the next link: Update resource in CKAN using python

Everything works great except the file is not updated correctly. Description, name, etc.. works great and the time of the dataset is correctly updated, but not the file.

This is the code I'm using against demo.ckan.org:

resource_dict_excel = {'id': '07153b0a-f330-4235-b28a-21bdfe8ff9ca',
                     'url':'http://myserver/ckan_api/public_html/test-excel.xls',
                     'format':'XLS', 
                     'description':'Descripción excel'}

    requests.post('http://demo.ckan.org/api/3/action/resource_update',
              json=resource_dict_excel,
              headers={"Authorization": "b2367ca2-567c-46b4-b714-67632ef906d5"})
    print resource_dict_excel

UPDATE

url="http://myserver/ckan_api/public_html/producction.xls"
f = urllib2.urlopen(url)
data = f.read()



requests.post('http://myckanserver/api/3/action/resource_update',
              data={"package_id":"90bc25e0-be1d-49a4-8e3a-c43d945bb9c1"},
              headers={"X-CKAN-API-Key": "2b367c89-924d-4086-8d76-1e6672bb0c23"},
              files=[('upload', data)])

Works correct!!!

Thanks

Community
  • 1
  • 1
davisoski
  • 727
  • 2
  • 14
  • 41
  • I've tried to answer below but it would be helpful how exactly you created the resource (also in Python?) and whether a file was ever uploaded and able-to-be downloaded or if you just specified a URL. – Matt Fullerton Feb 16 '17 at 11:03
  • Do you use Data Explorer? Does your configuration sends the file to a database so you can preview and filter it? Do you successfully upload this file using the interface? – neves Apr 16 '21 at 19:01

2 Answers2

2

I think there are multiple things going on here:

  • You can't just update a URL of a CKAN resource which thinks it is a file. The link returned by the api call is a ckan-internal link which returns the file uploaded for the resource. I do wonder though why it doesn't return anything (file not found) - you said the file remains the same, or did you just mean the URL?
  • You can't import a file by specifying a URL. There is a mechanism on some CKANs (Datapusher) which will fetch a URL and store the contents (tabular data, like XLS) in a database, but that is different. To upload a file to a CKAN in Python you need to specify it as file data and not a URL. There is an example here - it might work for resource_update too.
Matt Fullerton
  • 535
  • 3
  • 8
0

You can check all output log on your command "paster serve". Depending what installation process you used, the log will be available at "/var/log/ckan" or "/var/log/apache2".

  • Hi. Nothing is generated in /var/log/apache2, /var/log/jetty, /var/log/nginx, and /var/log/ckan not exist... thanks – davisoski Feb 15 '17 at 20:22
  • What type of installation do you follow? Can you send me? Try to run the CKAN server over port 5000. Try this command to start server: su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && paster serve --reload /etc/ckan/default/development.ini" – Luiz Felipe F M Costa Feb 16 '17 at 05:39