{"record":{"id":"3c7a905666435b09","repo":"nicolargo/glances","slug":"cannot-get-args-str-e","errorCode":null,"errorMessage":"Cannot get args ({str(e)})","messagePattern":"Cannot get args \\((.+?)\\)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"glances/outputs/glances_restful_api.py","lineNumber":1396,"sourceCode":"                    args_json[key] = '********'\n            args_json = {key: secure_option(key, value) for key, value in args_json.items()}\n        else:\n            for key in self._ALWAYS_REDACTED_ARGS:\n                if key in args_json and args_json[key]:\n                    args_json[key] = '********'\n        return args_json\n\n    def _api_args(self):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the JSON representation of the Glances command line arguments\n        HTTP/200 if OK\n        HTTP/404 if others error\n        \"\"\"\n        try:\n            args_json = self._sanitize_args()\n        except Exception as e:\n            raise HTTPException(status.HTTP_404_NOT_FOUND, f\"Cannot get args ({str(e)})\")\n\n        return GlancesJSONResponse(args_json)\n\n    def _api_args_item(self, item: str):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the JSON representation of the Glances command line arguments item\n        HTTP/200 if OK\n        HTTP/400 if item is not found\n        HTTP/404 if others error\n        \"\"\"\n        if item not in self.args:\n            raise HTTPException(status.HTTP_400_BAD_REQUEST, f\"Unknown argument item {item}\")\n\n        try:\n            args_json = self._sanitize_args()[item]\n        except Exception as e:\n            raise HTTPException(status.HTTP_404_NOT_FOUND, f\"Cannot get args item ({str(e)})\")","sourceCodeStart":1378,"sourceCodeEnd":1414,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/outputs/glances_restful_api.py#L1378-L1414","documentation":"HTTP 404 raised by GET /api/4/args when self._sanitize_args() throws while building the sanitized view of Glances' command-line arguments. The sanitization redacts credential-like keys; any exception inside it (e.g. an args attribute that cannot be serialized or a missing expected field) is converted into this 404.","triggerScenarios":"GET /api/4/args on an instance whose argparse namespace contains a value that breaks _sanitize_args() — typically a non-serializable object injected by a plugin or fork that adds custom CLI options.","commonSituations":"Custom Glances builds with extra CLI flags, or version skew between the API server and the client expectations after an upgrade changed the args namespace.","solutions":["Check the parenthesized str(e) for the offending attribute/operation","Upgrade/align the glances package so args parsing matches the API code","Reproduce locally: start glances in the same mode and call the endpoint to confirm which argument breaks sanitization","If you added custom args in a fork, make them str/int serializable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"r = requests.get(f'{base}/api/4/args', timeout=5)\nif r.status_code != 200:\n    raise RuntimeError(f'args endpoint broken: {r.text}')","typeGuard":null,"tryCatchPattern":"try:\n    args = requests.get(f'{base}/api/4/args').json()\nexcept requests.HTTPError as e:\n    if 'Cannot get args' in e.response.text:\n        log.error('glances server-side args serialization failed')\n    raise","preventionTips":["Keep glances core version consistent (no mixed files from different releases)","Avoid injecting non-serializable objects into the args namespace","Test /api/4/args right after deploying an upgrade"],"tags":["glances","rest-api","cli-args","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"}