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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...