From c020eea28fd39e938de3f2e2277f8e253767c664 Mon Sep 17 00:00:00 2001 From: Diana Huang <dkh@edx.org> Date: Tue, 10 Dec 2019 14:07:48 -0500 Subject: [PATCH] Handle case where incoming body may or may not be a unicode string. --- lti_consumer/outcomes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lti_consumer/outcomes.py b/lti_consumer/outcomes.py index 9f355d0..e166eb5 100644 --- a/lti_consumer/outcomes.py +++ b/lti_consumer/outcomes.py @@ -12,6 +12,7 @@ from xml.sax.saxutils import escape import six.moves.urllib.error import six.moves.urllib.parse +from six import text_type from lxml import etree from xblockutils.resources import ResourceLoader @@ -42,7 +43,8 @@ def parse_grade_xml_body(body): """ lti_spec_namespace = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0" namespaces = {'def': lti_spec_namespace} - data = body.strip().encode('utf-8') + if isinstance(body, text_type): + data = body.strip().encode('utf-8') try: parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8') # pylint: disable=no-member -- GitLab