Bug: Unable to find the file
tanmoyio opened this issue · 2 comments
tanmoyio commented
Describe the bug
index.upload() couldn't find the file (tried both relative and absolute path)
To Reproduce
import os
import splunklib.client as client
def splunk_connector(username, password, host):
try:
service = client.connect(host=host, username=username, password=password)
if service:
print("Splunk connection established")
return service
except Exception as e:
print(e)
def splunk_write(service, idx):
indexes = service.indexes
all_indexes_name = [index.name for index in indexes]
if idx not in all_indexes_name:
service_index = service.indexes.create(idx)
else:
service_index = service.indexes[idx]
service_index.upload('/home/misha/out.txt')
service = splunk_connector(
username=os.environ["USERNAME"],
password=os.environ["PASSWORD"],
host=os.environ["HOST"]
)
splunk_write(service, idx)Expected behavior
It should grab the file content and upload it to selected index
Logs or Screenshots
Splunk connection established
Traceback (most recent call last):
File "splunk_upload.py", line 33, in <module>
splunk_write(service, 'auth1m_out')
File "splunk_upload.py", line 24, in splunk_write
service_index.upload('/home/misha/out.txt')
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/client.py", line 2219, in upload
self.service.post(path, name=filename, **kwargs)
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/binding.py", line 291, in wrapper
return request_fun(self, *args, **kwargs)
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/binding.py", line 72, in new_f
val = f(*args, **kwargs)
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/binding.py", line 781, in post
response = self.http.post(path, all_headers, **query)
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/binding.py", line 1273, in post
return self.request(url, message)
File "/home/misha/miniconda3/envs/morpheus-22.11/lib/python3.8/site-packages/splunklib/binding.py", line 1302, in request
raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 400 Bad Request -- unable to open file: path='/home/misha/out.txt' error='No such file or directory'
Splunk (please complete the following information):
- Version: [e.g. 8.0.5]
- OS: [e.g. Ubuntu 20.04.1]
- Deployment: [e.g. single-instance]
SDK (please complete the following information):
- Version: [e.g. 1.6.14]
- Language Runtime Version: [e.g. Python 3.7]
- OS: [e.g. MacOS 10.15.7]
Additional context
Add any other context about the problem here.
akaila-splunk commented
akaila-splunk commented
Closing the Issue as we haven't received any response. @tanmoyio please reopen the Issue if you are still facing the issue.