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
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
Just to follow up, the official release on http://dev.splunk.com/view/python-sdk/ that contains this fix is now live.
Just to follow up, the official release on http://dev.splunk.com/view/python-sdk/ that contains this fix is now live.
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
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
Thanks, that fixed the issue.