Skip to content

Commit

Permalink
Decode to utf-8 to avoid UnicodeDecodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Nov 7, 2018
1 parent 856ce3d commit 982773f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions ckanext/xloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ckanext/xloader/job_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/xloader/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 982773f

Please sign in to comment.