nicolargo/glances · warning · HTTPException

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

Error message

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

What it means

Raised when get_raw_stats_item(item) fails, returned as HTTP 404. The plugin is known but the requested item could not be extracted — most often because the item name does not exist in the plugin's stats dict (KeyError) or the stats are not yet populated.

Source

Thrown at glances/outputs/glances_restful_api.py:1122

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

        Return the JSON 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))

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

        return GlancesJSONResponse(ret)

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

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. GET /api/4/<plugin> once and use exact item keys from the response
  2. Retry after the first refresh interval to rule out uninitialized stats
  3. Upgrade glances or pin the client to the field names of the deployed version

Example fix

// before
GET /api/4/cpu/total  // 404: item does not exist
// after
GET /api/4/cpu       // inspect keys, then
GET /api/4/cpu/total_percent
Defensive patterns

Strategy: validation

Validate before calling

keys = httpx.get(f'{BASE}/api/4/{plugin}').json().keys()  # or first element if list
assert item in keys, f'{item} not in {list(keys)}'

Type guard

def item_exists(item: str, plugin_stats: dict) -> bool:
    return isinstance(plugin_stats, dict) and item in plugin_stats

Try / catch

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

Prevention

When it happens

Trigger: GET /api/4/<plugin>/<item> with a nonexistent field name, e.g. /api/4/cpu/nonexistent, or querying an item before the first stats refresh completes.

Common situations: Clients using field names from older/newer glances versions (item names change across releases), or racing server startup.

Related errors


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