{"record":{"id":"ba77930666994415","repo":"nicolargo/glances","slug":"cannot-get-config-str-e","errorCode":null,"errorMessage":"Cannot get config ({str(e)})","messagePattern":"Cannot get config \\((.+?)\\)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"glances/outputs/glances_restful_api.py","lineNumber":1297,"sourceCode":"        except Exception as e:\n            raise HTTPException(\n                status.HTTP_404_NOT_FOUND, f\"Cannot get {item} = {value} for plugin {plugin} ({str(e)})\"\n            )\n        else:\n            return GlancesJSONResponse(ret)\n\n    def _api_config(self):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the JSON representation of the Glances configuration file\n        HTTP/200 if OK\n        HTTP/404 if others error\n        \"\"\"\n        try:\n            # Get the RAW value of the config' dict\n            args_json = self.config.as_dict() if self.args.password else self.config.as_dict_secure()\n        except Exception as e:\n            raise HTTPException(status.HTTP_404_NOT_FOUND, f\"Cannot get config ({str(e)})\")\n        else:\n            return GlancesJSONResponse(args_json)\n\n    def _api_config_section(self, section: str):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the JSON representation of the Glances configuration section\n        HTTP/200 if OK\n        HTTP/400 if item is not found\n        HTTP/404 if others error\n        \"\"\"\n        config_dict = self.config.as_dict() if self.args.password else self.config.as_dict_secure()\n        if section not in config_dict:\n            raise HTTPException(status.HTTP_400_BAD_REQUEST, f\"Unknown configuration item {section}\")\n\n        try:\n            # Get the RAW value of the config' dict\n            ret_section = config_dict[section]","sourceCodeStart":1279,"sourceCodeEnd":1315,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/outputs/glances_restful_api.py#L1279-L1315","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the parenthesized exception text — it names the underlying cause (e.g. InterpolationSyntaxError); fix the offending line in glances.conf and restart","Validate the config locally with python -c \"from glances.config import GlancesConfig; GlancesConfig().as_dict()\" before starting the server","If a plugin injects non-serializable values into config, report/patch the plugin; as_dict is expected to return JSON-safe data","As a last resort run with a minimal -C /path/to/clean.conf to isolate the bad section"],"exampleFix":"# before (glances.conf)\n[regexps] \n# ... a value containing a bare '%'\nfoo = 100%\n# after\nfoo = 100%%","handlingStrategy":"try-catch","validationCode":"# preflight: config serialization works\nimport requests\nr = requests.get('http://host:61208/api/4/config', timeout=5)\nassert r.status_code == 200, r.text","typeGuard":null,"tryCatchPattern":"try:\n    cfg = requests.get(f'{base}/api/4/config').json()\nexcept requests.HTTPError as e:\n    detail = e.response.json().get('detail', '')\n    if 'Cannot get config' in detail:\n        log.error('server config unreadable: %s', detail)\n    raise","preventionTips":["Keep glances.conf syntactically valid; escape % as %% in values","Validate config with a local as_dict() call before exposing the API","Monitor the API server log for the underlying exception"],"tags":["glances","rest-api","config","http-404","fastapi"],"backgroundTag":"http-404-not-found","analyzedSha":"a240d8dfb3105a38b5964357ec21768594b0e83e","analyzedAt":"2026-08-27T19:15:19.178Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}