{"record":{"id":"f8beed0934b926da","repo":"nicolargo/glances","slug":"jwt-authentication-is-not-available-install-pytho","errorCode":null,"errorMessage":"JWT authentication is not available. Install python-jose or check configuration.","messagePattern":"JWT authentication is not available\\. Install python-jose or check configuration\\.","errorType":"http","errorClass":"HTTPException","httpStatus":501,"severity":"error","filePath":"glances/outputs/glances_restful_api.py","lineNumber":811,"sourceCode":"\n        Generate a JWT access token for authenticated users.\n\n        Expected JSON body:\n        {\n            \"username\": \"string\",\n            \"password\": \"string\"\n        }\n\n        Returns:\n        {\n            \"access_token\": \"string\",\n            \"token_type\": \"bearer\",\n            \"expires_in\": int (seconds)\n        }\n        \"\"\"\n        # Check if JWT is available\n        if self._jwt_handler is None or not self._jwt_handler.is_available:\n            raise HTTPException(\n                status.HTTP_501_NOT_IMPLEMENTED,\n                \"JWT authentication is not available. Install python-jose or check configuration.\",\n            )\n\n        # Check if password authentication is enabled\n        if self._password is None:\n            raise HTTPException(\n                status.HTTP_501_NOT_IMPLEMENTED,\n                \"Password authentication is not enabled. Start Glances with --password option.\",\n            )\n\n        # Parse request body\n        try:\n            body = await request.json()\n        except Exception:\n            raise HTTPException(status.HTTP_400_BAD_REQUEST, \"Invalid JSON body\")\n\n        username = body.get('username')","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/outputs/glances_restful_api.py#L793-L829","documentation":"The /api/4/token endpoint raises HTTP 501 when self._jwt_handler is None or its is_available is False — meaning the JWT layer (python-jose dependency and/or a usable secret) isn't present, so token issuance is impossible. This mirrors the RuntimeError from GlancesJWT.create_access_token but is surfaced as an HTTP error.","triggerScenarios":"POST /api/4/token on a Glances started with --password but without python-jose installed or without a JWT secret configured. The endpoint checks availability before parsing the body, so the 501 comes back regardless of payload.","commonSituations":"pip installs of bare glances without the [api] extra; Docker images missing the dependency; upgrades that dropped python-jose; fresh installs where the secret generation step never ran.","solutions":["pip install 'glances[api]' (or pip install python-jose) on the server and restart Glances.","Run once with --password so the JWT secret is created/persisted.","Retry POST /api/4/token; if still 501, check glances.log for JWT init messages."],"exampleFix":"# before\npip install glances\nglaces -w --password\ncurl -X POST http://localhost:61208/api/4/token\n# 501 JWT authentication is not available\n\n# after\npip install 'glances[api]'\nglaces -w --password\ncurl -X POST http://localhost:61208/api/4/token -d '{\"username\":\"u\",\"password\":\"p\"}'","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec('jose') is None:\n    raise SystemExit(\"pip install 'glances[api]' to enable /api/4/token\")","typeGuard":null,"tryCatchPattern":"r = requests.post(f'{base}/api/4/token', json=creds)\nif r.status_code == 501:\n    raise SystemExit('server lacks JWT support — use Basic auth or install glances[api]')","preventionTips":["Include glances[api] in deployment requirements.","Smoke-test /api/4/token after deployment; a 501 means missing dependency/config.","Fall back to Basic auth when token issuance is unavailable."],"tags":["jwt","http-501","missing-dependency","rest-api"],"backgroundTag":"jwt-library-missing","analyzedSha":"a240d8dfb3105a38b5964357ec21768594b0e83e","analyzedAt":"2026-08-27T19:15:19.178Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}