From ee6a92de52111a4f461767b3d6640276d4c53f04 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Sat, 7 Jan 2017 16:33:48 +0100 Subject: [PATCH] Ensure suppressing urllib3 warning works correctly On some platforms (RHEL7 using ansible) the warnings are not being suppressed. Looking into this, the try-except block failed with the error `cannot import name InsecurePlatformWarning`. So it is safer to import and filter each warning individually. This fixes ansible/ansible#20006 --- winrm/transport.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/winrm/transport.py b/winrm/transport.py index bb2f881a..d1778334 100644 --- a/winrm/transport.py +++ b/winrm/transport.py @@ -1,8 +1,10 @@ from __future__ import unicode_literals from contextlib import contextmanager +import errno import re import sys import os +import time import weakref is_py2 = sys.version[0] == '2' @@ -189,7 +191,18 @@ def send_message(self, message): prepared_request = self.session.prepare_request(request) try: - response = self.session.send(prepared_request, timeout=self.read_timeout_sec) + + for retry in range(5): + try: + response = self.session.send(prepared_request, timeout=self.read_timeout_sec) + break + except requests.exceptions.ConnectionError as e: + if e.args[0].reason.errno != errno.ECONNREFUSED: + raise + elif retry == 4: + raise + time.sleep(5) + response_text = response.text response.raise_for_status() return response_text