From d232cfa5f94c71d013cf0c678b45734c701d1609 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Mon, 23 Sep 2019 15:08:29 -0400 Subject: [PATCH 1/2] Encode to bytes not decode to unicode. --- recommender/recommender.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/recommender/recommender.py b/recommender/recommender.py index 920527d..e1922e1 100644 --- a/recommender/recommender.py +++ b/recommender/recommender.py @@ -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 @@ -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 @@ -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 @@ -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}) @@ -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: From afd00cd387de685ba2fa601fd4c71a5f85dddd68 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Mon, 23 Sep 2019 15:10:30 -0400 Subject: [PATCH 2/2] Update version. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bdde8f4..6e0968c 100644 --- a/setup.py +++ b/setup.py @@ -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',