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!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...