Splunk Dev

Splunk python SDK to update kvstore error

kyaparla
Path Finder

Getting this error when using batch_save to update kvstore through Splunk python SDK.

This works fine when posting same content through curl, not sure if some limitation through splunk SDK. Anyone have any idea on quick fix?

File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/client.py", line 3724, in batch_save
return json.loads(self._post('batch_save', headers=KVStoreCollectionData.JSON_HEADER, body=data).body.read().decode('utf-8'))
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/client.py", line 3615, in _post
return self.service.post(self.path + url, owner=self.owner, app=self.app, sharing=self.sharing, **kwargs)
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/binding.py", line 289, in wrapper
return request_fun(self, *args, **kwargs)
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/binding.py", line 71, in new_f
val = f(*args, **kwargs)
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/binding.py", line 742, in post
response = self.http.post(path, all_headers, **query)
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/binding.py", line 1208, in post
return self.request(url, message)
File "/opt/splunk/etc/apps/adp_cmdb/bin/splunklib/binding.py", line 1228, in request
raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 400 Bad Request -- The provided query was invalid.

0 Karma

jrouse025
Path Finder

When you call the client.data.batch_save() be sure to put an asterisk in front of your passed parameter.
client.data.batch_save(*data)

You can see this in the unit tests:
https://github.com/splunk/splunk-sdk-python/blob/master/tests/test_kvstore_batch.py
unit test: def test_insert_find_update_data(self):

Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...