nicolargo/glances · error · HTTPException

Cannot get config ({str(e)})

Error message

Cannot get config ({str(e)})

What it means

Raised by the Glances REST API GET /api/4/config endpoint when serializing the configuration to a dict fails. The handler calls self.config.as_dict() (or as_dict_secure() when password auth is disabled) and wraps any exception into an HTTP 404 with the cause in the message. It almost always means the Glances configuration object is malformed or a config value cannot be converted, not that the URL is unknown.

Source

Thrown at glances/outputs/glances_restful_api.py:1297

        except Exception as e:
            raise HTTPException(
                status.HTTP_404_NOT_FOUND, f"Cannot get {item} = {value} for plugin {plugin} ({str(e)})"
            )
        else:
            return GlancesJSONResponse(ret)

    def _api_config(self):
        """Glances API RESTful implementation.

        Return the JSON representation of the Glances configuration file
        HTTP/200 if OK
        HTTP/404 if others error
        """
        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]

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. Read the parenthesized exception text — it names the underlying cause (e.g. InterpolationSyntaxError); fix the offending line in glances.conf and restart
  2. Validate the config locally with python -c "from glances.config import GlancesConfig; GlancesConfig().as_dict()" before starting the server
  3. If a plugin injects non-serializable values into config, report/patch the plugin; as_dict is expected to return JSON-safe data
  4. As a last resort run with a minimal -C /path/to/clean.conf to isolate the bad section

Example fix

# before (glances.conf)
[regexps] 
# ... a value containing a bare '%'
foo = 100%
# after
foo = 100%%
Defensive patterns

Strategy: try-catch

Validate before calling

# preflight: config serialization works
import requests
r = requests.get('http://host:61208/api/4/config', timeout=5)
assert r.status_code == 200, r.text

Try / catch

try:
    cfg = requests.get(f'{base}/api/4/config').json()
except requests.HTTPError as e:
    detail = e.response.json().get('detail', '')
    if 'Cannot get config' in detail:
        log.error('server config unreadable: %s', detail)
    raise

Prevention

When it happens

Trigger: GET /api/4/config when glances was started with a broken/partially parsed configuration file, or when a custom config parser plugin raised during as_dict()/as_dict_secure(). The real cause is visible only in the parenthesized str(e) part of the detail.

Common situations: Corrupted or hand-edited glances.conf, a config file with invalid interpolation tokens (e.g. bare % in configparser values), or running the API against a config that a plugin mutated with a non-serializable object.

Related errors


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