Alerting

Python script - module urllib.request error

antonioformato
Explorer

I'm experiencing issue running python script as trigger action.

I got error from urllib.request module:

x = urllib.request.urlopen('https://www.google.com/')
File "/opt/splunk/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/opt/splunk/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/opt/splunk/lib/python3.7/urllib/request.py", line 548, in _open
'unknown_open', req)
File "/opt/splunk/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/opt/splunk/lib/python3.7/urllib/request.py", line 1387, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>

 

If I run script from Python in OS it works.

Any idea?

Thanks

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

When you run the script in the OS, are you using the Splunk environment?

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

antonioformato
Explorer

No,

I'm using

#python3 myscript.py

running

#/opt/splunk/bin/python3.7 myscript.py

doesn't work

 

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust
Running the script using the instance of Python supplied by the OS is not a good test because it may not match the version supplied by Splunk and will not have the same libraries.
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...