Skip to content

Fix XML responses to not throw errors for unicode characters #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

loganknecht
Copy link
Contributor

Changed splunklib/data.py load function to convert text provided into a utf-8 string so that Python XML parser will not throw errors when processing utf-8 encoded responses.

Changed `splunklib/data.py` `load` function to convert text provided into a utf-8 string so that Python XML parser will not throw errors when processing utf-8 encoded responses.
…ncoded only for utf strings, so that Python XML parser will not throw errors when processing utf-8 encoded responses.
@@ -76,6 +77,12 @@ def load(text, match=None):
'namespaces': [],
'names': {}
}

# Convert to unicode encoding in only python 2 for xml parser
if sys.version_info < (3, 0, 0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use and and combine these into a single if

Copy link
Contributor

@shakeelmohamed shakeelmohamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one small change

if sys.version_info < (3, 0, 0):
if isinstance(text, unicode):
text = text.encode('utf-8')
if(sys.version_info < (3, 0, 0) and isinstance(text, unicode)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: outer parens aren't necessary but LGTM

@shakeelmohamed shakeelmohamed changed the base branch from master to develop June 7, 2018 21:55
@loganknecht loganknecht merged commit 05f789c into develop Jun 8, 2018
@skylasam skylasam deleted the bug/DVPL-7312-exceptions-raised-for-unicode-characters branch June 26, 2018 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants