nicolargo/glances · error · HTTPException

Unknown argument item {item}

Error message

Unknown argument item {item}

What it means

HTTP 400 raised by GET /api/4/args/{item} when the requested name is not an attribute of the Glances args namespace. The check is 'item not in self.args', i.e. membership on the argparse Namespace's __dict__, so any option name Glances was actually started with is accepted and anything else is rejected.

Source

Thrown at glances/outputs/glances_restful_api.py:1409

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

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

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. GET /api/4/args and pick an exact key from the returned JSON
  2. Check glances --help on the serving instance for valid option names
  3. Align client and server versions if the option exists only in a newer release
Defensive patterns

Strategy: validation

Validate before calling

args = requests.get(f'{base}/api/4/args').json()
if item not in args:
    raise KeyError(f'{item} not in args; valid: {sorted(args)}')

Type guard

def valid_arg(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 == 400:
        # unknown arg name
        ...

Prevention

When it happens

Trigger: GET /api/4/args/foo when --foo is not a Glances CLI option, or when querying an option added in a newer Glances version than the one serving the API.

Common situations: Version skew (client written for a newer Glances), typos in option names, or querying an option that only exists in a different run mode (e.g. server vs standalone).

Related errors


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