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
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...