Skip to content

Commit ed137b3

Browse files
committed
Overcome "Connection Refused" on some operations
So some operations on Windows actually cause the WinRM service to become unavailable for some time and WinRM currently cannot overcome this problem. Since this is a real problem to us when e.g. installing SCVMM on servers and we cannot influence the installer, here is the work-around we implemented. The current implementation simply tries 5 times with a 5 seconds delay, but YMMV. Ideally this is configurable by the user, and future defaults should be tested.
1 parent b1a54bc commit ed137b3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

winrm/transport.py

Lines changed: 12 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,16 @@ 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 retry == 4 or 'connection refused' in str(e).lower():
201+
raise
202+
time.sleep(5)
203+
193204
response_text = response.text
194205
response.raise_for_status()
195206
return response_text

0 commit comments

Comments
 (0)