AlistGo/alist · error

get token failed: %s

Error message

get token failed: %s

What it means

Raised during KodBox login (getToken) when the POST to /?user/index/loginSubmit returns an HTTP status >= 400. This is a transport/server-level failure before any JSON application code is even inspected — the raw response body is embedded as the error text.

Source

Thrown at drivers/kodbox/util.go:24

	"github.com/alist-org/alist/v3/pkg/utils"
	"github.com/go-resty/resty/v2"
	"strings"
)

func (d *KodBox) getToken() error {
	var authResp CommonResp
	res, err := base.RestyClient.R().
		SetResult(&authResp).
		SetQueryParams(map[string]string{
			"name":     d.UserName,
			"password": d.Password,
		}).
		Post(d.Address + "/?user/index/loginSubmit")
	if err != nil {
		return err
	}
	if res.StatusCode() >= 400 {
		return fmt.Errorf("get token failed: %s", res.String())
	}

	if res.StatusCode() == 200 && authResp.Code.(bool) == false {
		return fmt.Errorf("get token failed: %s", res.String())
	}

	d.authorization = fmt.Sprintf("%s", authResp.Info)
	return nil
}

func (d *KodBox) request(method string, pathname string, callback base.ReqCallback, noRedirect ...bool) ([]byte, error) {
	full := pathname
	if !strings.HasPrefix(pathname, "http") {
		full = d.Address + pathname
	}
	req := base.RestyClient.R()
	if len(noRedirect) > 0 && noRedirect[0] {
		req = base.NoRedirectClient.R()

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Verify d.Address: it must be the KodBox server root reachable over HTTP(S), e.g. https://kod.example.com
  2. Test manually: curl -X POST 'https://<address>/?user/index/loginSubmit' -d 'name=...&password=...' and confirm it is not 4xx/5xx
  3. Fix reverse-proxy/WAF rules that block the login POST, or KodBox rewrite rules if the endpoint 404s
Defensive patterns

Strategy: validation

Validate before calling

// Validate the address before adding the storage
u, err := url.Parse(cfg.Address)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
    return fmt.Errorf("invalid kodbox address: %q", cfg.Address)
}
resp, err := http.Head(cfg.Address + "/?user/index/loginSubmit")
if err != nil || resp.StatusCode >= 400 {
    return fmt.Errorf("kodbox login endpoint unreachable (status=%d)", resp.StatusCode)
}

Try / catch

if err := d.getToken(); err != nil {
    if strings.Contains(err.Error(), "get token failed") {
        // endpoint/server-level issue: do not retry with same config blindly
        return fmt.Errorf("check kodbox address/proxy: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: d.Address is wrong or unreachable, KodBox returns 404 (wrong path / missing rewrite rules), 500 (PHP error), 403 (WAF/firewall blocks the login endpoint), or the URL lacks the required scheme.

Common situations: Misconfigured site address in the storage config (missing http://, trailing slash issues, pointing at the file page instead of the server); reverse proxy blocking form POST login; KodBox installed without URL rewriting so /?user/index/loginSubmit 404s.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/f77405b57bae8324. Report an issue: GitHub.