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!

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...

Splunk AppDynamics Agents Webinar Series

Mark your calendars! On June 24th at 12PM PST, we’re going live with the second session of our Splunk ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2025 SplunkTrust is officially open! If you ...