From 084723abb71239e8a9be71b54dbaf1d035b4c6e3 Mon Sep 17 00:00:00 2001 From: Raphael Stolt Date: Mon, 16 Nov 2015 10:59:18 +0100 Subject: [PATCH] Catch JSONDecodeError when no JSON content --- ckanext/harvest/harvesters/ckanharvester.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ckanext/harvest/harvesters/ckanharvester.py b/ckanext/harvest/harvesters/ckanharvester.py index f041216..0dcb3b4 100644 --- a/ckanext/harvest/harvesters/ckanharvester.py +++ b/ckanext/harvest/harvesters/ckanharvester.py @@ -6,6 +6,7 @@ from ckan.model import Session, Package from ckan.logic import ValidationError, NotFound, get_action from ckan.lib.helpers import json from ckan.lib.munge import munge_name +from simplejson.scanner import JSONDecodeError from ckanext.harvest.model import HarvestJob, HarvestObject, HarvestGatherError, \ HarvestObjectError @@ -221,10 +222,13 @@ class CKANHarvester(HarvesterBase): try: content = self._get_content(url) + package_ids = json.loads(content) except ContentFetchError,e: self._save_gather_error('Unable to get content for URL: %s: %s' % (url, str(e)),harvest_job) return None - package_ids = json.loads(content) + except JSONDecodeError,e: + self._save_gather_error('Unable to decode content for URL: %s: %s' % (url, str(e)),harvest_job) + return None if org_filter_include: package_ids = set(package_ids) & include_pkg_ids