nicolargo/glances · error · AttributeError
{item}
Error message
{item} What it means
AttributeError raised by GlancesStats.__getattr__ (glances/stats.py:59) when code calls get_pluginsXXX_views()-style accessors: it resolves plugname from the attribute name, finds the plugin, but the plugin has no get_json_views method, so the fallback raises AttributeError(item). It is the dynamic plugin-dispatch protocol failing to find the expected method on the target plugin.
Source
Thrown at glances/stats.py:59
def __getattr__(self, item):
"""Overwrite the getattr method in case of attribute is not found.
The goal is to dynamically generate the following methods:
- getPlugname(): return Plugname stat in JSON format
- getViewsPlugname(): return views of the Plugname stat in JSON format
"""
# Check if the attribute starts with 'get'
if item.startswith('getViews'):
# Get the plugin name
plugname = item[len('getViews') :].lower()
# Get the plugin instance
plugin = self._plugins[plugname]
if hasattr(plugin, 'get_json_views'):
# The method get_json_views exist, return it
return getattr(plugin, 'get_json_views')
# The method get_views is not found for the plugin
raise AttributeError(item)
if item.startswith('get'):
# Get the plugin name
plugname = item[len('get') :].lower()
# Get the plugin instance
plugin = self._plugins[plugname]
if hasattr(plugin, 'get_json'):
# The method get_json exist, return it
return getattr(plugin, 'get_json')
# The method get_stats is not found for the plugin
raise AttributeError(item)
# Default behavior
raise AttributeError(item)
def load_modules(self, args):
"""Wrapper to load: plugins and export modules."""
# Init the plugins dict
# Active plugins dictionaryView on GitHub (pinned to a240d8dfb3)
Solutions
- Verify the target plugin class implements get_json_views (standard GlancesPluginModel subclasses do)
- Fix the accessor name — it must match an actual loaded plugin name exactly
- Update the custom plugin to inherit from Glances's plugin model
- Catch AttributeError around dynamic dispatch and skip that plugin
Example fix
# before
views = stats.get_myplugin_views()
# after
fn = getattr(stats, 'get_myplugin_views', None)
views = fn() if fn else {} Defensive patterns
Strategy: type-guard
Validate before calling
fn = getattr(stats, f'get_{name}_views', None)
views = fn() if callable(fn) else {} Type guard
def has_views_accessor(stats, plugin: str) -> bool:
return callable(getattr(stats, f'get_{plugin}_views', None)) Try / catch
try:
views = getattr(stats, f'get_{name}_views')()
except AttributeError:
views = {} Prevention
- Build accessor names from the actual loaded plugin list
- Derive custom plugins from the standard plugin model
- Guard every dynamic get* dispatch with getattr defaults
When it happens
Trigger: Calling stats.get_XYZ_views (or any get..._views accessor) where plugin XYZ exists but doesn't implement get_json_views — e.g. a plugin not derived from the standard model, or a typo where the plugin name resolves to something unexpected.
Common situations: Custom plugins missing the views API; version mixes where an old plugin lacks get_json_views; typos in dynamically constructed method names.
Related errors
- Cannot get help view data ({str(e)})
- Cannot get plugin {plugin} ({str(e)})
- '{self.__class__.__name__}' object has no key '{item}'
- Plugin {plugin} already in sys.modules, skipping (workaround
- Cannot get plugin list ({str(e)})
AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27).
Data as JSON: /api/errors/e295b96c28a938bf.
Report an issue: GitHub.