2016-06-07 112 views
0

我正在使用elasticsearch 2.3.1和python 2.7。我試圖創建一個簡單的實例,並測試作爲Elasticsearch:安裝屏蔽時無法使用python進行連接

esInstance = Elasticsearch(['https://'+shield_uname+":"+shield_pass+"@"+server+":"+port]) 

print esInstance.info() 

,但我得到

elasticsearch.exceptions.SSLError: ConnectionError(EOF occurred in violation of protocol (_ssl.c:590)) caused by: SSLError(EOF occurred in violation of protocol (_ssl.c:590)) 

我到底做錯了什麼?當我嘗試時出現同樣的錯誤

requests.get("https://"+shield_uname+":"+shield_pass+"@"+server+":"+port, verify=False) 

我該如何解決這個問題?

回答

1

我認爲你最好只是passing the fields as arguments,因爲你已經將它們作爲單獨的變量。

這是「最充分」的版本的認證。例如,您的變量插入:

# SSL client authentication using client_cert and client_key 

es = Elasticsearch(
    [server], 
    http_auth=(shield_uname, shield_pass), 
    port=port, 
    use_ssl=True, 
    verify_certs=True, 
    ca_certs='/path/to/cacert.pem', 
    client_cert='/path/to/client_cert.pem', 
    client_key='/path/to/client_key.pem', 
) 

注意的參數port都處理SSL後。如果你真的在使用證書,那麼你需要確定你已經告訴Python他們。如果您使用的是標準證書,則可以使用certifi,如上面的鏈接所示。

+0

謝謝,但我沒有任何證書或鑰匙在我身邊。我可以用use_ssl = False來使用http_auth嗎? – AbtPst

+0

是的,你可以使用'http_auth'而不使用SSL,但這確實意味着你的用戶名/密碼會以純文本的形式通過你的網絡(可以測試,但不能用於生產!)。這相當於使用'http',但要這樣做,您可以在'port'設置爲刪除SSL使用/設置後刪除所有內容。 – pickypg

+0

完美!這是我現在需要做的。謝謝 – AbtPst