|
|
@ -6,6 +6,7 @@ Avoids use of urllib2 due to lack of SNI support.
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from urllib import urlencode
|
|
|
|
from urllib import urlencode
|
|
|
@ -24,6 +25,8 @@ from lib.util import (
|
|
|
|
CommonConfig,
|
|
|
|
CommonConfig,
|
|
|
|
ApplicationError,
|
|
|
|
ApplicationError,
|
|
|
|
run_command,
|
|
|
|
run_command,
|
|
|
|
|
|
|
|
SubprocessError,
|
|
|
|
|
|
|
|
display,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +86,28 @@ class HttpClient(object):
|
|
|
|
|
|
|
|
|
|
|
|
cmd += [url]
|
|
|
|
cmd += [url]
|
|
|
|
|
|
|
|
|
|
|
|
stdout, _ = run_command(self.args, cmd, capture=True, always=self.always, cmd_verbosity=2)
|
|
|
|
attempts = 0
|
|
|
|
|
|
|
|
max_attempts = 3
|
|
|
|
|
|
|
|
sleep_seconds = 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# curl error codes which are safe to retry (request never sent to server)
|
|
|
|
|
|
|
|
retry_on_status = (
|
|
|
|
|
|
|
|
6, # CURLE_COULDNT_RESOLVE_HOST
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
attempts += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
stdout, _ = run_command(self.args, cmd, capture=True, always=self.always, cmd_verbosity=2)
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
except SubprocessError as ex:
|
|
|
|
|
|
|
|
if ex.status in retry_on_status and attempts < max_attempts:
|
|
|
|
|
|
|
|
display.warning(u'%s' % ex)
|
|
|
|
|
|
|
|
time.sleep(sleep_seconds)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
if self.args.explain and not self.always:
|
|
|
|
if self.args.explain and not self.always:
|
|
|
|
return HttpResponse(method, url, 200, '')
|
|
|
|
return HttpResponse(method, url, 200, '')
|
|
|
|