self.host =“ KibanaProxy”
self.Port =“ 443”
self.user =“ test”
self.password =“测试”
我需要禁止证书验证。在命令行上使用选项-k
时,它可以与curl配合使用。但是,当使用Elasticsearch python模块中的elasticsearch.Elasticsearch连接时,会引发错误。
_es2 = Elasticsearch([self.host], port=self.port, scheme="https", http_auth=(self.user, self.password), use_ssl=True, verify_certs=False)
_es2.info()
错误:
raise SSLError('N/A', str(e), e)
elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed (_ssl.c:590)) caused by: SSLError([SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590))```
答案 0 :(得分:0)
找到了。 在阅读这篇文章https://github.com/elastic/elasticsearch-py/issues/275时,我了解了connection_class。寻找与其相关的一些标准或预定义方法,因此找到了https://elasticsearch-py.readthedocs.io/en/master/transports.html
解决方案:
from elasticsearch import RequestsHttpConnection
.....
_es2 = Elasticsearch([self.host], port=self.port, connection_class=RequestsHttpConnection, http_auth=(self.user, self.password), use_ssl=True, verify_certs=False)
print(es.ping())
$ ./sn.py
是