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