I'm testing uploading a file using the Splunk Python SDK and receiving the following error :
Traceback (most recent call last):
File "testConnection.py", line 50, in
myindex.upload("/opt/splunkforwarder/bin/scripts/test");
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/client.py", line 2106, in upload
self.service.post(path, name=filename, **kwargs)
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/binding.py", line 289, in wrapper
return request_fun(self, *args, **kwargs)
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/binding.py", line 71, in new_f
val = f(*args, **kwargs)
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/binding.py", line 752, in post
response = self.http.post(path, all_headers, **query)
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/binding.py", line 1224, in post
return self.request(url, message)
File "/home/hafahmed/splunk-sdk-python-1.6.6/splunklib/binding.py", line 1244, in request
raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 400 Bad Request -- unable to open file: path='/opt/splunkforwarder/bin/scripts/test' error='No such file or directory'
Code snippet:
myindex = service.indexes["testing"]
myindex.upload("/opt/splunkforwarder/bin/scripts/test");
The file exists and has the correct permissions, Any hints?
I think the problem might be where the file is located, if the file is in another server it won't work. In other words, you first need to copy the file to Splunk SH server then you can upload it. Once the file is locally you can pass the path and call the function to upload the file.
SCP the file to /tmp folder then:
myindex = service.indexes["secdevops"]
uploadme = "/tmp/scoring_output.csv"
myindex.upload(uploadme);
unable to open file it's like permission problem ?
chmod a+x yourscript.py Or yourscrpit.sh
can you try ?
Your file does not have an extension. Splunk interprets files with no extension as binary files and will not ingest them.
hmm tried changing the extension but I'm still getting the same error
splunklib.binding.HTTPError: HTTP 400 Bad Request -- unable to open file: path='/opt/splunkforwarder/bin/scripts/test.txt' error='No such file or directory'
Can you post the actual lines of python code for the upload?
myindex = service.indexes["testing"]
uploadme = "/opt/splunkforwarder/bin/scripts/test.txt"
myindex.upload(uploadme)
This method does not use a path, it just uses a file name as parameter. Try to change the directory,and then try to use just "text.txt" as the parameter for the upload function. You can change the directory in python with os.chdir see example here: https://stackoverflow.com/questions/431684/how-do-i-change-directory-cd-in-python
Currently, you tried to upload a file that is called "opt/Splunk...." in your current working directory, that's why the file is not found.
Is the file and directory owned by splunk?
Hi,
is there no file extention like test.sh or test.py? Looks like your path is pointing to a folder, not a file.
Which permissions does the file have? Is it readable and executable?
it's actually pointing to a file and it's both readable and executable 😞