Skip to content

Commit 0941e35

Browse files
committed
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
1 parent b1a54bc commit 0941e35

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

winrm/transport.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import unicode_literals
22
from contextlib import contextmanager
3+
import errno
34
import re
45
import sys
56
import os
7+
import time
68
import weakref
79

810
is_py2 = sys.version[0] == '2'
@@ -189,7 +191,18 @@ def send_message(self, message):
189191
prepared_request = self.session.prepare_request(request)
190192

191193
try:
192-
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)
194+
195+
for retry in range(5):
196+
try:
197+
response = self.session.send(prepared_request, timeout=self.read_timeout_sec)
198+
break
199+
except requests.exceptions.ConnectionError as e:
200+
if e.args[0].reason.errno != errno.ECONNREFUSED:
201+
raise
202+
if retry == 4:
203+
raise
204+
time.sleep(5)
205+
193206
response_text = response.text
194207
response.raise_for_status()
195208
return response_text

0 commit comments

Comments
 (0)