2013-05-03 212 views
0

我試圖使用Splunk的python SDK(http://docs.splunk.com/Documentation/PythonSDK)連接到我的Splunk服務器,但我得到一個ParseError。當使用splunk python SDK無法連接到非本地主機

>>> 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正在返回;我測試了這個由離開了港口,這讓我:

錯誤:[錯誤60]操作超時

那麼,我究竟做錯了什麼?

回答

1

看起來您正在使用錯誤的端口。默認情況下,Splunk的管理端口爲8089.除非您更改了該內容,否則您應該使用8089而不是443.

另一種確認URL和憑據的方法是通過cURL從命令行進行測試您正在嘗試SDK的機器:

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

當然,這是問題,我在考慮https和那個服務器端口。謝謝,Neeraj。 – sophe 2013-05-03 17:12:06

相關問題