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

[utils] Handle JSON decode error in ckan_post

.json() may fail, see
parent 0becfca6d171
......@@ -34,11 +34,17 @@ def ckan_post(config, action, data=None):
url = urljoin(base, 'api/3/action/' + action)
headers = {'Authorization': config['ckan-api-key'],
'Content-Type': 'application/json'}
r =, headers=headers, data=json.dumps(data or {}))
if not r.ok:
error = r.json()['error']
raise CKANPostError('action %s failed: %s' % (action, error))
return r.json()['result']
resp =, headers=headers, data=json.dumps(data or {}))
jresp = resp.json()
except ValueError:
error = resp.text
if resp.ok:
return jresp['result']
error = jresp['error']
raise CKANPostError('action %s failed: %s' % (action, error))
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