nicolargo/glances · warning · HTTPException
Cannot get {item} unit for plugin {plugin} ({str(e)})
Error message
Cannot get {item} unit for plugin {plugin} ({str(e)}) What it means
Raised when get_item_info(item, 'unit') fails on the item-unit endpoint, returned as HTTP 404. Same metadata source as descriptions: the item must exist in the plugin's items description dict with a unit entry.
Source
Thrown at glances/outputs/glances_restful_api.py:1258
)
else:
return GlancesJSONResponse(ret)
def _api_item_unit(self, plugin: str, item: str):
"""Glances API RESTful implementation.
Return the JSON representation of the couple plugin/item unit
HTTP/200 if OK
HTTP/400 if plugin is not found
HTTP/404 if others error
"""
self._check_if_plugin_available(plugin)
try:
# Get the unit
ret = self.stats.get_plugin(plugin).get_item_info(item, 'unit')
except Exception as e:
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get {item} unit for plugin {plugin} ({str(e)})")
else:
return GlancesJSONResponse(ret)
def _api_value(self, plugin: str, item: str, value: str | int | float):
"""Glances API RESTful implementation.
Return the process stats (dict) for the given item=value
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 valueView on GitHub (pinned to a240d8dfb3)
Solutions
- Treat 404 as 'unitless' in client logic
- Check known items via /api/4/<plugin>/views
- Align with the deployed glances version's metadata
Example fix
# before
unit = fetch(f'/api/4/mem/{item}/unit').json() # 404 for unitless items
# after
r = fetch(f'/api/4/mem/{item}/unit')
unit = r.json() if r.ok else '' Defensive patterns
Strategy: fallback
Validate before calling
views = httpx.get(f'{BASE}/api/4/{plugin}/views').json()
has_unit = item in views Type guard
def has_unit(item: str, views: dict) -> bool:
return item in views Try / catch
r = httpx.get(f'{BASE}/api/4/{plugin}/{item}/unit')
unit = r.json() if r.status_code == 200 else '' # unitless fallback Prevention
- Treat missing units as unitless rather than an error
When it happens
Trigger: GET /api/4/<plugin>/<item>/unit for an item with no unit defined or not present in item metadata — e.g., counters or newly added fields.
Common situations: Clients auto-labeling units for every stat key; many items legitimately have no unit.
Related errors
- Cannot get {item} description for plugin {plugin} ({str(e)})
- Cannot get help view data ({str(e)})
- Cannot get plugin list ({str(e)})
- Cannot get stats ({str(e)})
- Cannot get limits ({str(e)})
AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27).
Data as JSON: /api/errors/6fbb0199052e4dc9.
Report an issue: GitHub.