Splunk Search

Force python3 on custom commands

cpm003
Path Finder

Hi all,
I´ve a custom command but it requieres python3 for launch properly.

Errors on job inspector:

09-17-2019 13:49:30.497 INFO  ChunkedExternProcessor - Running process: /opt/splunk/bin/python /opt/splunk/etc/apps/arcsightapi/bin/bypass.py
09-17-2019 13:49:30.666 ERROR ChunkedExternProcessor - stderr: Error in sitecustomize; set PYTHONVERBOSE for traceback:
09-17-2019 13:49:30.666 ERROR ChunkedExternProcessor - stderr: AttributeError: module 'sys' has no attribute 'setdefaultencoding'
09-17-2019 13:49:30.666 ERROR ChunkedExternProcessor - Failed attempting to parse transport header: module 'requests.packages.urllib3' has no attribute 'disable_warnings'

if i exec under terminal with python3 support works nice:

root@horsell:/opt/splunk/bin# ./splunk cmd python3 ../etc/apps/arcsightapi/bin/client.py  -h
Error in sitecustomize; set PYTHONVERBOSE for traceback:
AttributeError: module 'sys' has no attribute 'setdefaultencoding'
usage: client.py [-h] [-a AREA] [-s SOURCE] [-q SEARCH_QUERY]
                 [-ts START_QUERY] [-te END_QUERY] [-tl TIME_LIMIT]

Any idea to solve this?
Regards.

0 Karma

nilendra19888
Explorer

Hi ,

You can write a wrapper script to use the python3 available on your system to execute the custom commands.

import os
import subprocess

_NEW_PYTHON_PATH = '/opt/rh/python27/root/usr/bin'
_SPLUNK_PYTHON_PATH = os.environ['PYTHONPATH']

os.environ['PYTHONPATH'] = _NEW_PYTHON_PATH
my_process = os.path.join(os.getcwd(), 'test.py')

p = subprocess.Popen([os.environ['PYTHONPATH'], my_process, _SPLUNK_PYTHON_PATH],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()[0]
print output

0 Karma

kiril123
Path Finder

I have the same problem. It was working in 6.6 but not in 7.3.1

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Splunk will support python3 in an upcoming release.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...