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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...