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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...