From 982773fc421a557439889e77cbf48bf62e25ddcc Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Wed, 7 Nov 2018 14:29:06 +0100 Subject: [PATCH] Decode to utf-8 to avoid UnicodeDecodeError --- ckanext/xloader/cli.py | 11 +++++++---- ckanext/xloader/job_exceptions.py | 2 +- ckanext/xloader/jobs.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ckanext/xloader/cli.py b/ckanext/xloader/cli.py index 3df91124..53dee8a9 100644 --- a/ckanext/xloader/cli.py +++ b/ckanext/xloader/cli.py @@ -184,10 +184,13 @@ def _submit_resource(self, resource, user, indent=0): r=resource)) return dataset_ref = resource.get('package_name', resource['package_id']) - print('{indent}Submitting /dataset/{dataset}/resource/{r[id]}\n' - '{indent} url={r[url]}\n' - '{indent} format={r[format]}' - .format(dataset=dataset_ref, r=resource, indent=' ' * indent)) + print(u'{indent}Submitting /dataset/{dataset}/resource/{r[id]}\n' + u'{indent} url={url}\n' + u'{indent} format={format}' + .format(dataset=dataset_ref, + format=r['format'].decode('utf-8'), + url=r['url'].decode('utf-8'), + indent=' ' * indent)) data_dict = { 'resource_id': resource['id'], 'ignore_hash': True, diff --git a/ckanext/xloader/job_exceptions.py b/ckanext/xloader/job_exceptions.py index 09e311fe..0443c143 100644 --- a/ckanext/xloader/job_exceptions.py +++ b/ckanext/xloader/job_exceptions.py @@ -31,7 +31,7 @@ def __init__(self, message, status_code, request_url, response): def __str__(self): return u'{} status={} url={} response={}'.format( - self.message, self.status_code, self.request_url, self.response) \ + self.message.decode('utf-8'), self.status_code, self.request_url.decode('utf-8'), self.response) \ .encode('ascii', 'replace') class LoaderError(JobError): diff --git a/ckanext/xloader/jobs.py b/ckanext/xloader/jobs.py index 68f3bc30..17d66592 100644 --- a/ckanext/xloader/jobs.py +++ b/ckanext/xloader/jobs.py @@ -158,7 +158,7 @@ def xloader_data_into_datastore_(input, job_dict): ) # fetch the resource data - logger.info(u'Fetching from: {0}'.format(url)) + logger.info(u'Fetching from: {0}'.format(url.decode('utf-8'))) try: headers = {} if resource.get('url_type') == 'upload':