Splunk Dev

Getting errors when running a.py in Splunk Python SDK.

jrfreeze
Explorer

We use Splunk cloud and I'm trying to figure out how to use the Splunk Python SDK but I'm stuck on the first example. When I first ran a.py, I got the error:

NameError: name 'six' is not defined
Which I fixed by adding "as six" to "import splunklib.six.moves.http_client"

Now I'm stuck, getting the following when I enter python a.py:

Traceback (most recent call last):
File "a.py", line 30, in 
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
AttributeError: 'module' object has no attribute 'moves

Any thoughts?

Thank you.

Labels (2)
0 Karma

jrfreeze
Explorer

OK, this turned out to be a silly oversight. I had changed the "import" line, but then hadn't changed the actual connection definition is line 30 from:
connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
to
connection = six.HTTPSConnection(HOST, PORT)

Now that error is solved but I still can't seem to get connected via Python. I'm thinking I need to have greater permissions maybe? Here's the new traceback:

Traceback (most recent call last):
  File "a.py", line 43, in 
    connection.request("POST", "/services/auth/login", body, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1053, in request
    self._send_request(method, url, body, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1093, in _send_request
    self.endheaders(body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1049, in endheaders
    self._send_output(message_body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 893, in _send_output
    self.send(msg)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 855, in send
    self.connect()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1274, in connect
    server_hostname=server_hostname)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket
    _context=self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__
    self.do_handshake()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...