Skip to content

Commit

Permalink
Merge pull request #14 from edx/feanil/encode_not_decode
Browse files Browse the repository at this point in the history
Encode to bytes not decode to unicode.
  • Loading branch information
feanil authored Sep 23, 2019
2 parents 8c3f4a8 + afd00cd commit eb5e22d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions recommender/recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def _check_upload_file(self, request, file_types, file_type_error_msg, event, fi
response = Response()
tracker.emit(event, {'uploadedFileName': 'FILE_TYPE_ERROR'})
response.status = 415
response.body = json.dumps({'error': file_type_error_msg}).decode('utf-8')
response.body = json.dumps({'error': file_type_error_msg}).encode('utf-8')
response.headers['Content-Type'] = 'application/json'
return response

Expand All @@ -390,7 +390,7 @@ def _check_upload_file(self, request, file_types, file_type_error_msg, event, fi
response = Response()
tracker.emit(event, {'uploadedFileName': 'FILE_SIZE_ERROR'})
response.status = 413
response.body = json.dumps({'error': self.ugettext('Size of uploaded file exceeds threshold')}).decode('utf-8')
response.body = json.dumps({'error': self.ugettext('Size of uploaded file exceeds threshold')}).encode('utf-8')
response.headers['Content-Type'] = 'application/json'
return response

Expand All @@ -404,7 +404,7 @@ def _raise_pyfs_error(self, event):
error = self.ugettext('The configuration of pyfs is not properly set')
tracker.emit(event, {'uploadedFileName': 'IMPROPER_FS_SETUP'})
response.status = 404
response.body = json.dumps({'error': error}).decode('utf-8')
response.body = json.dumps({'error': error}).encode('utf-8')
response.headers['Content-Type'] = 'application/json'
return response

Expand Down Expand Up @@ -579,7 +579,7 @@ def upload_screenshot(self, request, _suffix=''): # pylint: disable=unused-argu
return self._raise_pyfs_error('upload_screenshot')

response = Response()
response.body = json.dumps({'file_name': str("fs://" + file_name)}).decode('utf-8')
response.body = json.dumps({'file_name': str("fs://" + file_name)}).encode('utf-8')
response.headers['Content-Type'] = 'application/json'
tracker.emit('upload_screenshot',
{'uploadedFileName': response.body})
Expand Down Expand Up @@ -883,14 +883,14 @@ def import_resources(self, request, _suffix=''):
data['recommendations'] = self.recommendations

tracker.emit('import_resources', {'Status': 'SUCCESS', 'data': data})
response.body = json.dumps(data, sort_keys=True).decode('utf-8')
response.body = json.dumps(data, sort_keys=True).encode('utf-8')
response.status = 200
return response
except (ValueError, KeyError):
response.status = 415
response.body = json.dumps(
{'error': self.ugettext('Please submit the JSON file obtained with the download resources button')}
).decode('utf-8')
).encode('utf-8')
tracker.emit('import_resources', {'Status': 'FILE_FORMAT_ERROR'})
return response
except IOError:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def package_data(pkg, root_list):

setup(
name='recommender-xblock',
version='1.4.3',
version='1.4.4',
description='recommender XBlock', # TODO: write a better description.
long_description=README,
author='edX',
Expand Down

0 comments on commit eb5e22d

Please sign in to comment.