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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...