nicolargo/glances · error · HTTPException

Cannot get args ({str(e)})

Error message

Cannot get args ({str(e)})

What it means

HTTP 404 raised by GET /api/4/args when self._sanitize_args() throws while building the sanitized view of Glances' command-line arguments. The sanitization redacts credential-like keys; any exception inside it (e.g. an args attribute that cannot be serialized or a missing expected field) is converted into this 404.

Source

Thrown at glances/outputs/glances_restful_api.py:1396

                    args_json[key] = '********'
            args_json = {key: secure_option(key, value) for key, value in args_json.items()}
        else:
            for key in self._ALWAYS_REDACTED_ARGS:
                if key in args_json and args_json[key]:
                    args_json[key] = '********'
        return args_json

    def _api_args(self):
        """Glances API RESTful implementation.

        Return the JSON representation of the Glances command line arguments
        HTTP/200 if OK
        HTTP/404 if others error
        """
        try:
            args_json = self._sanitize_args()
        except Exception as e:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get args ({str(e)})")

        return GlancesJSONResponse(args_json)

    def _api_args_item(self, item: str):
        """Glances API RESTful implementation.

        Return the JSON representation of the Glances command line arguments item
        HTTP/200 if OK
        HTTP/400 if item is not found
        HTTP/404 if others error
        """
        if item not in self.args:
            raise HTTPException(status.HTTP_400_BAD_REQUEST, f"Unknown argument item {item}")

        try:
            args_json = self._sanitize_args()[item]
        except Exception as e:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get args item ({str(e)})")

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. Check the parenthesized str(e) for the offending attribute/operation
  2. Upgrade/align the glances package so args parsing matches the API code
  3. Reproduce locally: start glances in the same mode and call the endpoint to confirm which argument breaks sanitization
  4. If you added custom args in a fork, make them str/int serializable
Defensive patterns

Strategy: try-catch

Validate before calling

r = requests.get(f'{base}/api/4/args', timeout=5)
if r.status_code != 200:
    raise RuntimeError(f'args endpoint broken: {r.text}')

Try / catch

try:
    args = requests.get(f'{base}/api/4/args').json()
except requests.HTTPError as e:
    if 'Cannot get args' in e.response.text:
        log.error('glances server-side args serialization failed')
    raise

Prevention

When it happens

Trigger: GET /api/4/args on an instance whose argparse namespace contains a value that breaks _sanitize_args() — typically a non-serializable object injected by a plugin or fork that adds custom CLI options.

Common situations: Custom Glances builds with extra CLI flags, or version skew between the API server and the client expectations after an upgrade changed the args namespace.

Related errors


AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27). Data as JSON: /api/errors/3c7a905666435b09. Report an issue: GitHub.