[utils] Properly handle ckan-baseurl
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 21 Nov 2014 16:33:31 +0100
changeset 15 f0c22bd9116d
parent 14 50e1c7ac3e59
child 16 4d8fea13570d
[utils] Properly handle ckan-baseurl In particular, when it does not have a trailing /.
utils.py
--- a/utils.py	Wed Nov 19 14:45:39 2014 +0100
+++ b/utils.py	Fri Nov 21 16:33:31 2014 +0100
@@ -16,7 +16,7 @@
 """cubicweb-cg33catsi utilities"""
 
 import json
-from urllib import basejoin
+from urlparse import urljoin
 
 import requests
 
@@ -28,7 +28,10 @@
 
 
 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'],
                'Content-Type': 'application/json'}
     r = requests.post(url, headers=headers, data=json.dumps(data or {}))