nicolargo/glances · error · HTTPException

Cannot get item {item} in config section {section} ({str(e)}

Error message

Cannot get item {item} in config section {section} ({str(e)})

What it means

HTTP 404 raised by GET /api/4/config/{section}/{item} when the item key does not exist inside an existing section (or the value fetch raises). This is the normal 'item not found' signal: the section was valid, but the option name inside it is unknown or empty.

Source

Thrown at glances/outputs/glances_restful_api.py:1343

        HTTP/200 if OK
        HTTP/400 if item is not found
        HTTP/404 if others error
        """
        config_dict = self.config.as_dict() if self.args.password else self.config.as_dict_secure()
        if section not in config_dict:
            raise HTTPException(status.HTTP_400_BAD_REQUEST, f"Unknown configuration item {section}")

        try:
            # Get the RAW value of the config' dict section
            ret_section = config_dict[section]
        except Exception as e:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get config section {section} ({str(e)})")

        try:
            # Get the RAW value of the config' dict item
            ret_item = ret_section[item]
        except Exception as e:
            raise HTTPException(
                status.HTTP_404_NOT_FOUND, f"Cannot get item {item} in config section {section} ({str(e)})"
            )

        return GlancesJSONResponse(ret_item)

    # Args keys that must always be redacted (even for authenticated users)
    _ALWAYS_REDACTED_ARGS = frozenset({'password'})

    # Args keys redacted when no authentication is configured
    # Note: keys matching the shared sensitive pattern (password, token, username...)
    # are redacted by secure_option(), only the ones it can not express are listed here.
    _SENSITIVE_ARGS = frozenset(
        {
            'password',
            'snmp_community',
            'snmp_user',
            'snmp_auth',
            'conf_file',

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. GET /api/4/config/{section} and inspect the returned keys to find the exact option name
  2. Add the option explicitly to the section in glances.conf and restart glances so it appears in the dict
  3. Remember options absent from the file are absent from the API — Glances does not merge internal defaults into this view

Example fix

# before
curl http://localhost:61208/api/4/config/influxdb/host
# 404 if 'host' unset; set it first, or list keys
curl http://localhost:61208/api/4/config/influxdb
Defensive patterns

Strategy: validation

Validate before calling

sec = requests.get(f'{base}/api/4/config/{section}').json()
if isinstance(sec, dict) and item not in sec:
    print('item not set in config file; using default')

Type guard

def has_item(section: str, item: str) -> bool:
    sec = requests.get(f'{base}/api/4/config/{section}').json()
    return isinstance(sec, dict) and item in sec

Try / catch

try:
    val = requests.get(f'{base}/api/4/config/{section}/{item}').json()
except requests.HTTPError as e:
    if e.response.status_code == 404:
        val = DEFAULTS.get((section, item))
    else:
        raise

Prevention

When it happens

Trigger: GET /api/4/config/cpu/zzz, or any request where {section} exists but the option was never set in glances.conf (configparser omits unset options).

Common situations: Querying defaults that were never explicitly written into the config file, or misspelled option names.

Related errors


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