Skip to content

Additional headers on every request and fix unicode decoding issue #209

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

abroglesc
Copy link
Contributor

@abroglesc abroglesc commented Jun 13, 2018

Summary of Changes

  • POST requests already allowed optional headers to be specified and added to the request. This adds the same functionality to GET requests in binding.py
  • Adds the ability when instantiating a splunklib.client to be able pass in additional headers that will be applied to all requests to the Splunk API with that client
  • Fixed a bug I was receiving when retrieving search results from my Splunk instance's API by adding the optional argument 'xmlcharrefreplace' flag to the .decode('utf-8') method.
  • Better organization and grouping of imports in binding.py and client.py

The stack trace I was receiving when hitting the decode bug is:

Traceback (most recent call last):
  File "snap_test.py", line 9, in <module>
    for app in service.apps:
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/client.py", line 1262, in __iter__
    for item in self.iter(**kwargs):
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/client.py", line 1426, in iter
    items = self._load_list(response)
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/client.py", line 1332, in _load_list
    entries = _load_atom_entries(response)
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/client.py", line 202, in _load_atom_entries
    r = _load_atom(response)
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/client.py", line 197, in _load_atom
    return data.load(response.body.read().decode('utf-8'), match)
  File "/Users/abroglesc/projects/splunk-sdk-python/splunklib/data.py", line 79, in load
    root = XML(text)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1311, in XML
    parser.feed(text)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1657, in feed
    self._parser.Parse(data, 0)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 102577: ordinal not in range(128)

@abroglesc
Copy link
Contributor Author

bump bump. Could someone take a look at this?

@shakeelmohamed
Copy link
Contributor

Thanks @abroglesc, we will take a look this week

@shakeelmohamed shakeelmohamed merged commit 711b895 into splunk:develop Jun 28, 2018
@shakeelmohamed
Copy link
Contributor

shakeelmohamed commented Jun 28, 2018

Thanks @abroglesc!

@abroglesc
Copy link
Contributor Author

Thanks for merging!

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.

2 participants