Skip to content

Commit de14732

Browse files
Fix retry (#509)
1 parent b096f80 commit de14732

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

linodecli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from .cli import CLI
2626
from .completion import bake_completions, get_completions
27+
from .configuration import ENV_TOKEN_NAME
2728
from .helpers import handle_url_overrides
2829
from .output import OutputMode
2930

linodecli/api_request.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ def do_request(
9393
if ctx.debug_request:
9494
_print_response_debug_info(result)
9595

96-
if _check_retry(result) and ctx.no_retry and ctx.retry_count < 3:
96+
while _check_retry(result) and not ctx.no_retry and ctx.retry_count < 3:
9797
time.sleep(_get_retry_after(result.headers))
9898
ctx.retry_count += 1
99-
do_request(ctx, operation, args, filter_header, skip_error_handling)
99+
result = method(url, headers=headers, data=body, verify=API_CA_PATH)
100100

101101
_attempt_warn_old_version(ctx, result)
102102

@@ -377,16 +377,12 @@ def _check_retry(response):
377377
# request timed out or rate limit exceeded
378378
return True
379379

380-
if (
380+
return (
381381
response.headers
382382
and response.status_code == 400
383383
and response.headers.get("Server") == "nginx"
384384
and response.headers.get("Content-Type") == "text/html"
385-
):
386-
# nginx html response
387-
return True
388-
389-
return False
385+
)
390386

391387

392388
def _get_retry_after(headers):

tests/unit/test_api_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def json_func():
477477
output = stderr_buf.getvalue()
478478
assert "" == output
479479

480-
def test_do_request_recursion(self, mock_cli, list_operation):
480+
def test_do_request_retry(self, mock_cli, list_operation):
481481
mock_response = Mock(status_code=408)
482482
with patch(
483483
"linodecli.api_request.requests.get", return_value=mock_response

0 commit comments

Comments
 (0)