Splunk Dev

External search command 'mypythonfile' returned error code 1 after Splunk upgrade

harshal_chakran
Builder

Hi,
I am trying to run a python file in search command.

|script python mypythonfile

I was able to run it the Splunkversion 6.0 before. But when I shifed to 6.1, I am getting the following error while running the command:

External search command 'mypythonfile' returned error code 1.

I made the changes in commands.conf too.

[mypythonfile]
filename= mypythonfile.py

Following is my mypythonfile.py file:

from pprint import pprint
import socket
import sys
import os
import time
import csv
import glob
import unicodedata
import Constants
import shutil
import splunklib.client as client
import splunklib.results as results
from xml.dom import minidom
from utils import error, parse
from time import sleep
from array import array
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
import SplunkMethods
import ParsingAndFilteredCSV
import Utilities
import BSC
import Cell
import Network
import WeakPerforming
import threading
from splunklib.modularinput import *
from sys import exit
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
def main(): ####MY CODE######
try:
except:
import traceback
stack = traceback.format_exc()
results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))
if __name__ == "__main__":
main()

Kindly Help...!!!

Tags (3)
0 Karma

praveenkpatidar
Explorer

Hello Harshal,

It seems the indentation is not correct in the python. To get this correct use below URL to check for Indent related errors. Package related errors are fine.
Once you resolve indent related errors, then you can use the file for custom commands.

https://www.tutorialspoint.com/execute_python_online.php

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...