From f02f5bf0492326e6ed23738ed5ddbb9c6b734b9c Mon Sep 17 00:00:00 2001 From: Tobias Macey Date: Wed, 16 Dec 2020 15:19:13 -0500 Subject: [PATCH] Fixing encoding of header row for posting to remote gradebook Posting to the remote gradebook via lmod proxy was failing due to a key error when parsing the CSV content. This was due to erroneously encoding a string object. This commit adds a check for the type of the header value to prevent double encoding it. --- lms/djangoapps/remote_gradebook/task_helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/remote_gradebook/task_helpers.py b/lms/djangoapps/remote_gradebook/task_helpers.py index d6b5d00ff583..9db8aa233e91 100644 --- a/lms/djangoapps/remote_gradebook/task_helpers.py +++ b/lms/djangoapps/remote_gradebook/task_helpers.py @@ -22,7 +22,8 @@ def create_datatable_csv(csv_file, datatable): """Creates a CSV file from the contents of a datatable.""" writer = csv.writer(csv_file, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL) - encoded_row = [str(s).encode('utf-8') for s in datatable['header']] + encoded_row = [s if isinstance(s, str) else str(s).encode('utf-8') + for s in datatable['header']] writer.writerow(encoded_row) for datarow in datatable['data']: # 's' here may be an integer, float (eg score) or string (eg student name)