nicolargo/glances · error · HTTPException

Cannot get args item ({str(e)})

Error message

Cannot get args item ({str(e)})

What it means

HTTP 404 raised by GET /api/4/args/{item} when building the sanitized args dict and indexing it for {item} fails. Because the preceding membership check already confirmed the attribute exists, this fires only if _sanitize_args() drops or renames the key during redaction, or throws while computing the value.

Source

Thrown at glances/outputs/glances_restful_api.py:1414

            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)})")

        return GlancesJSONResponse(args_json)

    def _api_set_extended_processes(self, pid: str):
        """Glances API RESTful implementation.

        Set the extended process stats for the given PID
        HTTP/200 if OK
        HTTP/400 if PID is not found
        HTTP/404 if others error
        """
        process_stats = glances_processes.get_stats(int(pid))

        if not process_stats:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Unknown PID process {pid}")

        glances_processes.extended_process = process_stats

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. GET /api/4/args and read the value from the full sanitized dict instead of the item endpoint
  2. If you need the raw value, restart glances with --password so sanitization keeps sensitive keys
  3. Upgrade glances if the sanitizer is known to drop legit keys in your version

Example fix

# before
curl http://localhost:61208/api/4/args/username
# after
curl http://localhost:61208/api/4/args | jq .username
Defensive patterns

Strategy: fallback

Validate before calling

args = requests.get(f'{base}/api/4/args').json()
value = args.get(item)  # avoids item endpoint entirely

Type guard

def arg_available(name: str) -> bool:
    return name in requests.get(f'{base}/api/4/args').json()

Try / catch

try:
    val = requests.get(f'{base}/api/4/args/{item}').json()
except requests.HTTPError as e:
    if e.response.status_code == 404:
        val = requests.get(f'{base}/api/4/args').json().get(item)
    else:
        raise

Prevention

When it happens

Trigger: GET /api/4/args/password-adjacent-key where the key exists in self.args but _sanitize_args() removes/redacts it so the [item] lookup raises KeyError; or sanitization itself errors.

Common situations: Querying credentials-related args on an unauthenticated instance — the sanitizer redacts them and the index may miss; or custom forks whose sanitizer doesn't preserve all keys.

Related errors


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