nicolargo/glances · warning · HTTPException

Not authenticated

Error message

Not authenticated

What it means

When the REST API runs with --password and a request carries no Authorization header at all, FastAPI's HTTPBasic yields no credentials, so Glances raises 401 'Not authenticated' with WWW-Authenticate: Basic to trigger the browser login dialog. It's the standard challenge response, not a malfunction — though programmatic clients see it as an error.

Source

Thrown at glances/outputs/glances_restful_api.py:468

        if self._jwt_handler is not None and self._jwt_handler.is_available:
            auth_header = request.headers.get("Authorization", "")
            if auth_header.lower().startswith("bearer "):
                token = auth_header.split(" ", 1)[1]
                username = self._jwt_handler.verify_token(token)
                if username is not None and username == self.args.username:
                    return username
                # Invalid Bearer token - reject immediately
                raise HTTPException(
                    status.HTTP_401_UNAUTHORIZED,
                    "Incorrect authentication",
                    {"WWW-Authenticate": "Bearer"},
                )

        # Fall back to Basic Auth
        # If no credentials provided (basic_creds is None), trigger browser dialog
        if basic_creds is None:
            # Force HTTPBasic auto_error behavior to trigger browser auth dialog
            raise HTTPException(
                status.HTTP_401_UNAUTHORIZED,
                "Not authenticated",
                {"WWW-Authenticate": "Basic"},
            )

        if basic_creds.username == self.args.username:
            if self._password.check_password(self.args.password, self._password.get_hash(basic_creds.password)):
                return basic_creds.username

        # Invalid credentials
        raise HTTPException(
            status.HTTP_401_UNAUTHORIZED,
            "Incorrect authentication",
            {"WWW-Authenticate": "Basic"},
        )

    def _logo(self):
        return rf"""

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. Send basic auth: curl -u user:pass http://host:61208/api/4/...
  2. Or obtain and send a Bearer token via POST /api/4/token.
  3. Configure credentials in whatever client (browser will prompt and remember).

Example fix

# before
curl http://host:61208/api/4/cpu
# 401 Not authenticated

# after
curl -u nicolargo:secret http://host:61208/api/4/cpu
Defensive patterns

Strategy: fallback

Validate before calling

if args.password:  # server runs authenticated
    client = requests.Session()
    client.auth = (username, password)  # always attach credentials

Try / catch

r = requests.get(url)
if r.status_code == 401 and 'WWW-Authenticate: Basic' in r.headers.get('WWW-Authenticate', ''):
    r = requests.get(url, auth=(user, pwd))

Prevention

When it happens

Trigger: Accessing any /api/4/* endpoint (or the web UI) of a password-protected Glances without credentials: plain curl http://host:61208/api/4/version, opening in a browser (dialog appears), or a monitoring scraper that forgot auth.

Common situations: Grafana/Netdata-style pollers pointed at Glances without configuring basic auth; browser first visit; scripts after password mode was newly enabled.

Understand the failure class

Related errors


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