Fix Python 2.7 response with unicode characters
@@ -308,6 +308,12 @@ class ContentDecodePolicy(SansIOHTTPPolicy):
raise DecodeError(message="JSON is invalid: {}".format(err), response=response, error=err)
elif "xml" in (content_type or []):
try:
+ try:
+ if isinstance(data, unicode): # type: ignore
+ # If I'm Python 2.7 and unicode XML will scream if I try a "fromstring" on unicode string
+ data_as_str = data_as_str.encode(encoding="utf-8") # type: ignore
+ except NameError:
+ pass
return ET.fromstring(data_as_str)
except ET.ParseError:
# It might be because the server has an issue, and returned JSON with
