Splunk Dev

problem with python splunk-sdk autologin

sathiyamoorthy
Explorer

Logging in using autologin=True in python splunk-sdk and executing a query gives ResponseReader object as expected if the session is not terminated,

>>> import splunklib.client as splunkclient
>>> splunk_service = splunkclient.connect(host='searchhead.com', port=8089, username='admin', password='password', autologin=True)
>>> splunk_service.jobs.oneshot("search index=myindex", earliest_time='-1hour')
<splunklib.binding.ResponseReader object at 0xaa2a10>

To terminate the session restarted the splunk search head service in searchhead.com, it restarted splunkd, splunkweb, etc.. tried the following after splunk related services are started.

Cross checked ports are connected and ready. But the query execution fails with some internal error?

>>> splunk_service.jobs.oneshot("search index=myindex", earliest_time='-1hour')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/splunklib/client.py", line 2799, in oneshot
    **params).body
  File "/usr/lib/python2.6/site-packages/splunklib/client.py", line 743, in post
    **query)
  File "/usr/lib/python2.6/site-packages/splunklib/binding.py", line 248, in wrapper
    return request_fun()
  File "/usr/lib64/python2.6/contextlib.py", line 34, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.6/site-packages/splunklib/binding.py", line 180, in _handle_auth_error
    yield
  File "/usr/lib/python2.6/site-packages/splunklib/binding.py", line 248, in wrapper
    return request_fun()
  File "/usr/lib/python2.6/site-packages/splunklib/binding.py", line 61, in new_f
    val = f(*args, **kwargs)
TypeError: post() takes at least 2 arguments (0 given)

But trying again immediately succeeds, (able to reproduce, first try after restart of splunk service always fails and second succeeds):

>>> splunk_service.jobs.oneshot("search index=myindex", earliest_time='-1hour')
<splunklib.binding.ResponseReader object at 0xaa2e50>

Is it a known issue? quick googling doesn't help much. Any help towards resolving this issue much appreciated.

PS: Splunk 6, tried in both splunk-sdk 1.2.0 and 1.0.0

Tags (2)
0 Karma
1 Solution

David_Noble_at_
Explorer

Thanks for reporting this issue. It is a bug and I have a fix in hand. We will include it in the next Python SDK release.

Here's what you need to do to make the change yourself.

  • Get the current Python SDK: version 1.2.1

  • At splunklib/binding.py, line 248 change:

                return request_fun()
    

    to

                return request_fun(self, *args, **kwargs)
    
  • Feel free to e-mail me directly, if you'd like additional help resolving this issue.

Thanks for using Splunk and the Splunk SDK

Best,

David Noble

dnoble@splunk.com

View solution in original post

abrown_splunk
Splunk Employee
Splunk Employee

Just to follow up, the official release on http://dev.splunk.com/view/python-sdk/ that contains this fix is now live.

0 Karma

abrown_splunk
Splunk Employee
Splunk Employee

Just to follow up, the official release on http://dev.splunk.com/view/python-sdk/ that contains this fix is now live.

0 Karma

David_Noble_at_
Explorer

I thought you'd like to know I pushed the splunk-sdk-1.2.2 release to GitHub. This release includes two things: the fix to the bug you found and a new acceptance test to cover your scenario. You can download splunk-sdk-pypthon-1.2.2 from GitHub at https://github.com/splunk/splunk-sdk-python right now. Our Web publishing team will be posting to http://dev.splunk.com/view/python-sdk/ soon.

Best,
David Noble

0 Karma

David_Noble_at_
Explorer

Thanks for reporting this issue. It is a bug and I have a fix in hand. We will include it in the next Python SDK release.

Here's what you need to do to make the change yourself.

  • Get the current Python SDK: version 1.2.1

  • At splunklib/binding.py, line 248 change:

                return request_fun()
    

    to

                return request_fun(self, *args, **kwargs)
    
  • Feel free to e-mail me directly, if you'd like additional help resolving this issue.

Thanks for using Splunk and the Splunk SDK

Best,

David Noble

dnoble@splunk.com

sathiyamoorthy
Explorer

Thanks, that fixed the issue.

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...