nicolargo/glances · error · HTTPException
Cannot get config section {section} ({str(e)})
Error message
Cannot get config section {section} ({str(e)}) What it means
Raised as HTTP 404 by GET /api/4/config/{section} when fetching the value of a section that passed the membership check still fails. Because the membership check already ran on the same dict, hitting this branch in practice means an exotic failure during dict access (custom dict subclass, concurrent config mutation between the check and the read) rather than a normal missing key.
Source
Thrown at glances/outputs/glances_restful_api.py:1317
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()
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]View on GitHub (pinned to a240d8dfb3)
Solutions
- Retry the request once — a transient race with config reload usually clears
- Inspect the parenthesized str(e) to identify the real exception type from the custom config class
- If you maintain a custom config class, make __getitem__ behave like a plain dict's
Defensive patterns
Strategy: retry
Try / catch
for attempt in range(2):
r = requests.get(f'{base}/api/4/config/{section}')
if r.status_code != 404 or 'Cannot get config section' not in r.text:
break
time.sleep(0.2) Prevention
- Avoid swapping self.config while serving requests
- Treat this 404 as transient; retry once before failing
When it happens
Trigger: GET /api/4/config/{section} where config_dict[section] raises — e.g. the config dict was replaced/reloaded concurrently, or a custom config implementation overrides __getitem__ and raises.
Common situations: Extremely rare; seen with plugins that swap self.config at runtime or with patched Glances versions using non-standard config classes.
Related errors
- Cannot get config ({str(e)})
- Cannot get item {item} in config section {section} ({str(e)}
- Cannot get help view data ({str(e)})
- Cannot get plugin list ({str(e)})
- Cannot get stats ({str(e)})
AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27).
Data as JSON: /api/errors/ea8e110fa3383286.
Report an issue: GitHub.