Commit c1c1e30c authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[utils] Properly handle ckan-baseurl

In particular, when it does not have a trailing /.
parent 50e1c7ac3e59
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"""cubicweb-cg33catsi utilities""" """cubicweb-cg33catsi utilities"""
import json import json
from urllib import basejoin from urlparse import urljoin
import requests import requests
...@@ -28,7 +28,10 @@ class CKANPostError(Exception): ...@@ -28,7 +28,10 @@ class CKANPostError(Exception):
def ckan_post(config, action, data=None): def ckan_post(config, action, data=None):
url = basejoin(config['ckan-baseurl'], 'api/3/action/' + action) base = config['ckan-baseurl']
if not base.endswith('/'):
base += '/'
url = urljoin(base, 'api/3/action/' + action)
headers = {'Authorization': config['ckan-api-key'], headers = {'Authorization': config['ckan-api-key'],
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
r = requests.post(url, headers=headers, data=json.dumps(data or {})) r = requests.post(url, headers=headers, data=json.dumps(data or {}))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment