nicolargo/glances · warning · HTTPException

Cannot get item {item} for key {key} in plugin {plugin} ({st

Error message

Cannot get item {item} for key {key} in plugin {plugin} ({str(e)})

What it means

Raised when get_raw_stats_key(item, key) fails on the nested key endpoint, returned as HTTP 404. This drills into list-of-dict stats (e.g., a specific NIC inside network stats); failure means the item or the inner key lookup raised — typically a missing key inside a dict-valued stat.

Source

Thrown at glances/outputs/glances_restful_api.py:1147

    def _api_key(self, plugin: str, item: str, key: str):
        """Glances API RESTful implementation.

        Return the JSON representation of  plugin/item/key
        HTTP/200 if OK
        HTTP/400 if plugin is not found
        HTTP/404 if others error
        """
        self._check_if_plugin_available(plugin)

        # Update the stat
        self.__update_stats(get_plugin_dependencies(plugin))

        try:
            # Get the RAW value of the stat views
            # TODO in #3211: use a non existing (to be created) get_export_key instead but break API
            ret = self.stats.get_plugin(plugin).get_raw_stats_key(item, key)
        except Exception as e:
            raise HTTPException(
                status.HTTP_404_NOT_FOUND,
                f"Cannot get item {item} for key {key} in plugin {plugin} ({str(e)})",
            )

        return GlancesJSONResponse(ret)

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

        Return the JSON view representation of the couple plugin/item
        HTTP/200 if OK
        HTTP/400 if plugin is not found
        HTTP/404 if others error
        """
        self._check_if_plugin_available(plugin)

        # Update the stat
        self.__update_stats(get_plugin_dependencies(plugin))

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. GET /api/4/<plugin>/<item> first and use exact inner key names
  2. Confirm the item actually contains dict values (not a scalar)
  3. Retry after a stats refresh if the item list can vary over time

Example fix

// before
GET /api/4/network/eth0/speed // 404
// after
GET /api/4/network           // see structure: [{interface_name, speed, ...}]
GET /api/4/network/interface_name/eth0
Defensive patterns

Strategy: validation

Validate before calling

data = httpx.get(f'{BASE}/api/4/{plugin}/{item}').json()
assert isinstance(data, (dict, list)), 'item has no nested keys'

Type guard

def has_inner_keys(data) -> bool:
    return isinstance(data, dict) or (isinstance(data, list) and data and isinstance(data[0], dict))

Try / catch

try:
    val = httpx.get(f'{BASE}/api/4/{plugin}/{item}/{key}').json()
except httpx.HTTPStatusError as e:
    if e.response.status_code == 404:
        val = None
    else:
        raise

Prevention

When it happens

Trigger: GET /api/4/<plugin>/<item>/<key> with a bad item or key, e.g. /api/4/network/interface_name/tx/typo, or when the item is a scalar with no inner keys.

Common situations: Iterating keys discovered from a different glances version, or assuming all items are dict/list-of-dict when some are scalars.

Related errors


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