使用 splunk python SDK 时无法连接到非本地主机

问题描述 投票:0回答:2

我正在尝试使用 Splunk 的 python SDK (http://docs.splunk.com/Documentation/PythonSDK) 连接到我的 Splunk 服务器,但出现了 ParseError。

>>> pip install splunk-sdk
>>> import splunklib.binding as binding
>>> cargs = {}
>>> cargs['host'] = 'splunk.mydomain.com'
>>> cargs['scheme'] = 'https'
>>> cargs['port'] = 443
>>> cargs['username'] = 'my_username'
>>> cargs['password'] = 'my_password'
>>> c = binding.connect(**cargs)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/myframework/lib/python2.7/site-packages/splunklib/binding.py", line 867, in connect
    c.login()
  File "/myframework/lib/python2.7/site-packages/splunklib/binding.py", line 753, in login
    session = XML(body).findtext("./sessionKey")
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1302, in XML
    return parser.close()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1655, in close
    self._raiseerror(v)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

所以返回到 connect() 的任何页面都没有预期的“./sessionKey”文本。我见过的所有示例都使用“localhost”作为主机,所以我不确定这个外部主机是否存在问题。我希望我能拿到返回的页面。

这台主机在我公司的网络上,所以应该没有访问问题。

Something 正在返回;我通过省略端口来测试这个,这让我:

错误:[Errno 60] 操作超时

那么,我在这里做错了什么?

python python-2.7 splunk
2个回答
1
投票

看起来你使用了错误的端口。默认情况下,Splunk 的管理端口是 8089。除非您更改了它,否则您应该使用 8089 而不是 443。

另一种确认 URL 和凭据的方法是在您尝试使用 SDK 的同一台机器上通过命令行通过 cURL 对其进行测试:

curl -k https://splunk.mydomain.com:8089/services/auth/login -d username=my_username -d password=my_password

0
投票

实际上,我正在尝试使用端口 443 的域 api,因为它是安全的,但没有用。然后它在使用端口 8089 后工作正常(即使它是安全连接)。

非常感谢@Neeraj。

© www.soinside.com 2019 - 2024. All rights reserved.