I am trying to connect using the example:
import splunklib.client as client
# Create a Service instance and log in
with client.connect(
host="http://myhost",
port=0000,
username="me",
password="my password") as conn:
# Print installed apps to the console to verify login
for app in conn.apps:
print app.name
But I am getting the following error:
Traceback (most recent call last):
File "C:/Users/anshanno/PycharmProjects/splunkTest/splunkSDKtest.py", line 8, in <module>
password="my password") as conn:
File "C:\Python27\lib\site-packages\splunk_sdk-1.6.0-py2.7.egg\splunklib\client.py", line 321, in connect
s.login()
File "C:\Python27\lib\site-packages\splunk_sdk-1.6.0-py2.7.egg\splunklib\binding.py", line 857, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "C:\Python27\lib\site-packages\splunk_sdk-1.6.0-py2.7.egg\splunklib\binding.py", line 1201, in post
return self.request(url, message)
File "C:\Python27\lib\site-packages\splunk_sdk-1.6.0-py2.7.egg\splunklib\binding.py", line 1218, in request
response = self.handler(url, message, **kwargs)
File "C:\Python27\lib\site-packages\splunk_sdk-1.6.0-py2.7.egg\splunklib\binding.py", line 1357, in request
connection.request(method, path, body, head)
File "C:\Python27\lib\httplib.py", line 1053, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1093, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 893, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 855, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1266, in connect
HTTPConnection.connect(self)
File "C:\Python27\lib\httplib.py", line 832, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
Has anyone else experienced this or know what is causing the issue? I have replaced my connection info for obvious reasons 🙂
Any help is appreciated.
I am having the same error: "gaierror: [Errno 11004] getaddrinfo failed"
However, none of the suggestions here have helped me resolve it. Here's my code:
import os
import splunklib.client as client
service = client.connect(host='https://<my_company_login_portal>.splunkcloud.com',
port=8089,
username=os.environ['SPLUNK_USERNAME'],
password=os.environ['SPLUNK_PASSWORD'])
I've confirmed that:
Any direction on this error is appreciated. Thanks!
What is the error that you are getting?
Actually, try this
from splunklib.client import connect as client
import os
service = client(host='https://<my_company_login_portal>.splunkcloud.com',
port=8089,
username=os.environ['SPLUNK_USERNAME'],
password=os.environ['SPLUNK_PASSWORD'])
Your code is the same as what I have above. I tried it anyways. Still didn't work. 😞
I believe that error means it couldn't resolve/reach your host.
EDIT: I had the wrong port and my user doesn't have privileges
Thanks @thejeffreystone! Yeah, I saw that in my search before I posted here. The solution that they gave was to use the IP address which threw the same error for me. I probably Should have included this in my question.
If it cannot find the host could that indicate an issue with permissions?
haha...I was working on my response and didnt see you have found it. Glad you got it.
Sorry to waste your time. It wouldn't let me post an update because I don't have enough rep.
No waste. I learned a new way of doing something.
or perhaps a firewall/routing issue somewhere. I was suspecting dns when I first read it, but you already disproved that. It's been a while since I encountered that in python. I did some testing in one of the example scripts and can't get the same error. So perhaps in this context its not resolution but something else. I think it is for sure in your connection attempt.
When I pass bad host names I get:
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
I'm using python 2.7.11 for reference and the same version of the sdk.
So now I am not so sure. I tested connecting to splunk cloud and to a local instance using the .splunkrc file and the stail.py example in the sdk.
I couldn't get your script to work. But I modified the info.py script provided to provide the connection info in the script. Not sure if this will format right:
from splunklib.client import connect
from splunklib.results import ResultsReader
# Create a Service instance and log in
service = connect(
host='host.com',
port=8089,
username='admin',
password='mypass')
content = service.info
for key in sorted(content.keys()):
value = content[key]
if isinstance(value, list):
print "%s:" % key
for item in value: print " %s" % item
else:
print "%s: %s" % (key, value)
print "Settings:"
content = service.settings.content
for key in sorted(content.keys()):
value = content[key]
print " %s: %s" % (key, value)