Splunk Dev

Splunk Python API - ValueError: Invalid IPv6 URL

vas123
Explorer

I am trying to coonect splunk using the below python code, but I get below errors. Any idea what am I doing wrong?
I have the following version of python and Splunk SDK installed.

splunk-sdk 1.6.6
python 3.6 (64bit)

import splunklib.client as client

HOST = 'https://ecomsplunk.mydomain.com'
PORT = '443'
USERNAME = 'user'
PASSWORD = 'password'
try:
# Create a Service instance and log in
service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD)
except Exception as url_exception:
print("Exception Unable to connect " + str(url_exception))

Traceback (most recent call last):
File "C:\Users\splunk_test.py", line 17, in
password=PASSWORD)
File "C:\Users\splunklib\client.py", line 331, in connect
s.login()
File "C:\Users\site-packages\splunklib\binding.py", line 872, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "C:\Users\site-packages\splunklib\binding.py", line 1224, in post
return self.request(url, message)
File "C:\Users\site-packages\splunklib\binding.py", line 1241, in request
response = self.handler(url, message, **kwargs)
File "C:\Users\site-packages\splunklib\binding.py", line 1366, in request
scheme, host, port, path = _spliturl(url)
File "C:\Users\site-packages\splunklib\binding.py", line 1071, in _spliturl
parsed_url = urllib.parse.urlparse(url)
File "C:\Users\urllib\parse.py", line 368, in urlparse
splitresult = urlsplit(url, scheme, allow_fragments)
File "C:\Users\urllib\parse.py", line 441, in urlsplit
raise ValueError("Invalid IPv6 URL")
ValueError: Invalid IPv6 URL
Press any key to continue . . .

Tags (2)
0 Karma
1 Solution

vas123
Explorer

I was able to get it resolve my problem by using the following code:

import splunklib.client as client

HOST = 'ecomsplunk.mydomain.com'
PORT = '8089'
USERNAME = 'user'
PASSWORD = 'password'
try:

Create a Service instance and log in

service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD,
scheme='https')
except Exception as url_exception:
print("Exception Unable to connect " + str(url_exception))

View solution in original post

vas123
Explorer

I was able to get it resolve my problem by using the following code:

import splunklib.client as client

HOST = 'ecomsplunk.mydomain.com'
PORT = '8089'
USERNAME = 'user'
PASSWORD = 'password'
try:

Create a Service instance and log in

service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD,
scheme='https')
except Exception as url_exception:
print("Exception Unable to connect " + str(url_exception))

Get Updates on the Splunk Community!

Splunk App for Anomaly Detection End of Life Announcment

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...