Splunk Dev

why the Python can be ran by alert, but can not ran manually

michael_wong
Path Finder

I have a script that can be ran with alert, but if I run the script manually, the following error will showed. Any idea how I can run it manually?

I have add the python location in first line.

#!/data/splunk/bin/python

[root@hostname scripts]# ./REST_1.py
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/data/splunk/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/data/splunk/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
Traceback (most recent call last):
File "./REST_1.py", line 7, in <module>
import requests
File "/data/splunk/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/data/splunk/lib/python2.7/site-packages/requests/utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "/data/splunk/lib/python2.7/site-packages/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/data/splunk/lib/python2.7/site-packages/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/data/splunk/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py", line 16, in <module>
from .connectionpool import (
File "/data/splunk/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 36, in <module>
from .connection import (
File "/data/splunk/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 43, in <module>
from .util import (
File "/data/splunk/lib/python2.7/site-packages/requests/packages/urllib3/util/__init__.py", line 10, in <module>
from .ssl_ import (
File "/data/splunk/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py", line 2, in <module>
from hashlib import md5, sha1
ImportError: cannot import name sha1

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

When running your scripts manually, be sure to do so in the Splunk environment.

splunk cmd python REST_1.py
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

When running your scripts manually, be sure to do so in the Splunk environment.

splunk cmd python REST_1.py
---
If this reply helps you, Karma would be appreciated.
0 Karma

michael_wong
Path Finder

It works, thank you for your help!

Tags (1)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...