infiniflow/ragflow · error · AuthException

Register failed: {msg}

Error message

Register failed: {msg}

What it means

Raised by register_user in the admin test client when POST /users (with API base) returns code != 0 and the message does not contain 'has already registered'. It wraps the server's rejection message, e.g. invalid email format, weak password, or nickname conflicts. The 'already registered' case is treated as success (idempotent) and silently returns.

Source

Thrown at admin/client/user.py:57

            cipher = Cipher_pkcs1_v1_5.new(rsa_key)
            password_base64 = base64.b64encode(line.encode("utf-8")).decode("utf-8")
            encrypted_password = cipher.encrypt(password_base64.encode())
            return base64.b64encode(encrypted_password).decode("utf-8")
    except Exception as exc:
        raise AuthException("Password encryption unavailable; install pycryptodomex (uv sync --python 3.13 --group test).") from exc
    return crypt(password_plain)


def register_user(client: HttpClient, email: str, nickname: str, password: str) -> None:
    password_enc = encrypt_password(password)
    payload = {"email": email, "nickname": nickname, "password": password_enc}
    res = client.request_json("POST", "/users", use_api_base=True, auth_kind=None, json_body=payload)
    if res.get("code") == 0:
        return
    msg = res.get("message", "")
    if "has already registered" in msg:
        return
    raise AuthException(f"Register failed: {msg}")


def login_user(client: HttpClient, server_type: str, email: str, password: str) -> str:
    password_enc = encrypt_password(password)
    payload = {"email": email, "password": password_enc}
    if server_type == "admin":
        response = client.request("POST", "/admin/login", use_api_base=True, auth_kind=None, json_body=payload)
    else:
        response = client.request("POST", "/auth/login", use_api_base=True, auth_kind=None, json_body=payload)
    try:
        res = response.json()
    except Exception as exc:
        raise AuthException(f"Login failed: invalid JSON response ({exc})") from exc
    if res.get("code") != 0:
        raise AuthException(f"Login failed: {res.get('message')}")
    token = response.headers.get("Authorization")
    if not token:
        raise AuthException("Login failed: missing Authorization header")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Read the embedded server message — it states the exact rejection reason
  2. Verify the email/nickname/password values satisfy server-side validation rules
  3. Confirm the API base URL and that POST /users is the correct registration endpoint for this server build
  4. If the account exists, the duplicate case auto-passes; otherwise fix the reported field and re-run
Defensive patterns

Strategy: try-catch

Validate before calling

import re

EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")

def is_valid_registration(email: str, nickname: str, password: str) -> bool:
    return bool(EMAIL_RE.match(email)) and bool(nickname.strip()) and len(password) >= 6

if not is_valid_registration(email, nickname, password):
    raise ValueError("Fix email/nickname/password before calling register_user")

Type guard

def is_user_error(res: dict) -> bool:
    """True when the server rejected the payload for a user-fixable reason."""
    return res.get("code") != 0 and "has already registered" not in res.get("message", "")

Try / catch

try:
    register_user(client, email, nickname, password)
except AuthException as e:
    msg = str(e)
    if "already registered" in msg:
        pass  # idempotent bootstrap — treat as success
    elif "email" in msg.lower() or "password" in msg.lower():
        fix_credentials_and_retry()  # user-fixable validation error
    else:
        raise  # server/config issue — surface it

Prevention

When it happens

Trigger: POST {email, nickname, password(base64/encrypted)} to /users returning non-zero code with a message other than duplicate registration — e.g. malformed email, password fails policy, tenant limits, or a validation error from the API server.

Common situations: Admin CLI/bootstrap scripts against a server whose password policy rejects the generated password; wrong API base URL hitting a route that returns a different error envelope; server version where registration is disabled.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/00c45f863ef6ab64. Report an issue: GitHub.