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

[email protected]

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

[email protected]

sathiyamoorthy
Explorer

Thanks, that fixed the issue.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...

Level Up Your Workflow: Mastering Splunk Cloud Management via Terraform

Tech Talk Recap   From Chaos to Control: Scaling Splunk Cloud with Infrastructure as Code Managing apps in ...