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!

Thanks for the Memories: .conf26 Took Learning to New Heights

Thank you, Splunk Community, for making .conf26 in Denver one for the books. From packed Splunk University ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...