nicolargo/glances · error · HTTPException

Unknown configuration item {section}

Error message

Unknown configuration item {section}

What it means

Returned as HTTP 400 by GET /api/4/config/{section} when the requested section name is not a top-level key of the configuration dict. The endpoint first builds the full config dict (as_dict or as_dict_secure) and then checks membership, so unknown or redacted-away sections are rejected before any value lookup.

Source

Thrown at glances/outputs/glances_restful_api.py:1311

        try:
            # Get the RAW value of the config' dict
            args_json = self.config.as_dict() if self.args.password else self.config.as_dict_secure()
        except Exception as e:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get config ({str(e)})")
        else:
            return GlancesJSONResponse(args_json)

    def _api_config_section(self, section: str):
        """Glances API RESTful implementation.

        Return the JSON representation of the Glances configuration section
        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
            ret_section = config_dict[section]
        except Exception as e:
            raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get config section {section} ({str(e)})")

        return GlancesJSONResponse(ret_section)

    def _api_config_section_item(self, section: str, item: str):
        """Glances API RESTful implementation.

        Return the JSON representation of the Glances configuration section/item
        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()

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. List valid sections first via GET /api/4/config and use an exact key from that response
  2. Check which config file glances loaded (command line / startup log) and confirm the section is spelled identically, case-sensitive
  3. If the section is sensitive, restart glances with password auth enabled so as_dict() (full) is used instead of as_dict_secure()

Example fix

# before
curl http://localhost:61208/api/4/config/influxdb
# after (discover valid sections first)
curl http://localhost:61208/api/4/config
curl http://localhost:61208/api/4/config/influxdb2
Defensive patterns

Strategy: validation

Validate before calling

sections = requests.get(f'{base}/api/4/config').json()
if section not in sections:
    raise SystemExit(f'unknown section {section}; valid: {list(sections)}')

Type guard

def valid_section(name: str, sections: dict) -> bool:
    return name in sections

Try / catch

try:
    r = requests.get(f'{base}/api/4/config/{section}')
    r.raise_for_status()
except requests.HTTPError as e:
    if e.response.status_code == 400:
        # unknown section
        ...

Prevention

When it happens

Trigger: GET /api/4/config/foo when [foo] does not exist in glances.conf. Also when the section exists but is hidden by as_dict_secure() because glances runs without --password and the section is considered sensitive.

Common situations: Typos in section names, querying sections that only exist in a different config file than the one glances was started with (-C flag), or querying credential-bearing sections on an unauthenticated instance.

Related errors


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