Splunk Dev

Python Script reading another file

mrlandis3
Path Finder

I am using a Python scripted input that needs to read from a text file an encoded username and password. The script then writes the results from an API call to a JSON file. So the pseudocode looks like this:

with open('key.txt', 'r') as file:
    set username and password

data = API call

with open('json', 'w') as file2:
    write data

My script is throwing an error saying that the key.txt file does not exist when it is definitely in the same directory. Are there any permission issues that could be causing this?

Labels (1)
0 Karma
1 Solution

mrlandis3
Path Finder

Issue has been fixed, the scripts required the absolute file path since the python file is not running from the context of the folder it is stored in.

View solution in original post

0 Karma

mrlandis3
Path Finder

Issue has been fixed, the scripts required the absolute file path since the python file is not running from the context of the folder it is stored in.

0 Karma
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...