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!

Index This | What did the zero say to the eight?

June 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...