diff --git a/linodecli/__init__.py b/linodecli/__init__.py index 5d76d385f..84d4926bb 100755 --- a/linodecli/__init__.py +++ b/linodecli/__init__.py @@ -24,6 +24,7 @@ ) from .cli import CLI from .completion import bake_completions, get_completions +from .configuration import ENV_TOKEN_NAME from .helpers import handle_url_overrides from .output import OutputMode diff --git a/linodecli/api_request.py b/linodecli/api_request.py index ae614413d..f3c77e60b 100644 --- a/linodecli/api_request.py +++ b/linodecli/api_request.py @@ -93,10 +93,10 @@ def do_request( if ctx.debug_request: _print_response_debug_info(result) - if _check_retry(result) and ctx.no_retry and ctx.retry_count < 3: + while _check_retry(result) and not ctx.no_retry and ctx.retry_count < 3: time.sleep(_get_retry_after(result.headers)) ctx.retry_count += 1 - do_request(ctx, operation, args, filter_header, skip_error_handling) + result = method(url, headers=headers, data=body, verify=API_CA_PATH) _attempt_warn_old_version(ctx, result) @@ -376,16 +376,12 @@ def _check_retry(response): # request timed out or rate limit exceeded return True - if ( + return ( response.headers and response.status_code == 400 and response.headers.get("Server") == "nginx" and response.headers.get("Content-Type") == "text/html" - ): - # nginx html response - return True - - return False + ) def _get_retry_after(headers): diff --git a/linodecli/baked/response.py b/linodecli/baked/response.py index 90a2bc388..6a20da23e 100644 --- a/linodecli/baked/response.py +++ b/linodecli/baked/response.py @@ -208,7 +208,7 @@ def __init__(self, response): ) else: self.attrs = _parse_response_model(response.schema) - self.rows = response.schema.extensions.get("linode-cli-rows") + self.rows = response.extensions.get("linode-cli-rows") self.nested_list = response.extensions.get("linode-cli-nested-list") self.subtables = response.extensions.get("linode-cli-subtables") @@ -216,6 +216,7 @@ def fix_json(self, json): """ Formats JSON from the API into a list of rows """ + if self.rows: return self._fix_json_rows(json) if self.nested_list: diff --git a/tests/unit/test_api_request.py b/tests/unit/test_api_request.py index ecf8dbd7a..9172bbbbd 100644 --- a/tests/unit/test_api_request.py +++ b/tests/unit/test_api_request.py @@ -477,7 +477,7 @@ def json_func(): output = stderr_buf.getvalue() assert "" == output - def test_do_request_recursion(self, mock_cli, list_operation): + def test_do_request_retry(self, mock_cli, list_operation): mock_response = Mock(status_code=408) with patch( "linodecli.api_request.requests.get", return_value=mock_response