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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...