From c3fd04b5db7877585d6a504526bb53bff1ac7f19 Mon Sep 17 00:00:00 2001 From: Alvaro Olmedo Date: Wed, 11 Dec 2019 00:15:49 +0100 Subject: [PATCH] Disable InsecureRequestWarning from urllib3's connectionpool with ssl_show_warn option --- elasticsearch/connection/http_requests.py | 4 ++++ elasticsearch/connection/http_urllib3.py | 1 + 2 files changed, 5 insertions(+) diff --git a/elasticsearch/connection/http_requests.py b/elasticsearch/connection/http_requests.py index e8fc2224..ce079654 100644 --- a/elasticsearch/connection/http_requests.py +++ b/elasticsearch/connection/http_requests.py @@ -103,6 +103,10 @@ class RequestsHttpConnection(Connection): ) self.session.verify = ca_certs + if not ssl_show_warn: + requests.packages.urllib3.disable_warnings() + + self.ssl_show_warn = ssl_show_warn if self.use_ssl and not verify_certs and ssl_show_warn: warnings.warn( "Connecting to %s using SSL with verify_certs=False is insecure." diff --git a/elasticsearch/connection/http_urllib3.py b/elasticsearch/connection/http_urllib3.py index 9f112fa2..52755f00 100644 --- a/elasticsearch/connection/http_urllib3.py +++ b/elasticsearch/connection/http_urllib3.py @@ -142,6 +142,7 @@ class Urllib3HttpConnection(Connection): or client_cert or client_key or ssl_version + or ssl_show_warn ): warnings.warn( "When using `ssl_context`, all other SSL related kwargs are ignored"