{"record":{"id":"75599767f95c5d94","repo":"AlistGo/alist","slug":"can-not-get-captcha","errorCode":null,"errorMessage":"can not get captcha","messagePattern":"can not get captcha","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/cloudreve/util.go","lineNumber":127,"sourceCode":"\t\t}\n\t\tif err.Error() != \"CAPTCHA not match.\" {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn err\n}\n\nfunc (d *Cloudreve) doLogin(needCaptcha bool) error {\n\tvar captchaCode string\n\tvar err error\n\tif needCaptcha {\n\t\tvar captcha string\n\t\terr = d.request(http.MethodGet, \"/site/captcha\", nil, &captcha)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif len(captcha) == 0 {\n\t\t\treturn errors.New(\"can not get captcha\")\n\t\t}\n\t\ti := strings.Index(captcha, \",\")\n\t\tdec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(captcha[i+1:]))\n\t\tvRes, err := base.RestyClient.R().SetMultipartField(\n\t\t\t\"image\", \"validateCode.png\", \"image/png\", dec).\n\t\t\tPost(setting.GetStr(conf.OcrApi))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif jsoniter.Get(vRes.Body(), \"status\").ToInt() != 200 {\n\t\t\treturn errors.New(\"ocr error:\" + jsoniter.Get(vRes.Body(), \"msg\").ToString())\n\t\t}\n\t\tcaptchaCode = jsoniter.Get(vRes.Body(), \"result\").ToString()\n\t}\n\tvar resp Resp\n\terr = d.request(http.MethodPost, loginPath, func(req *resty.Request) {\n\t\treq.SetBody(base.Json{\n\t\t\t\"username\":    d.Addition.Username,","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/cloudreve/util.go#L109-L145","documentation":"Thrown by Cloudreve doLogin when the site requires a captcha for login, the GET /site/captcha call technically succeeded, but the returned captcha string is empty. Without a captcha image the driver cannot OCR it, so login aborts before ever sending credentials.","triggerScenarios":"Cloudreve has login captcha enabled; doLogin(needCaptcha=true) calls GET /site/captcha; the response decodes to an empty string (server-side captcha generation failure, rate limiting, or an error envelope that was silently unmarshalled to empty).","commonSituations":"Cloudrebve version change where /site/captcha only issues a captcha per session/ticket that was already consumed; login attempts hammered in a loop consuming the captcha; reverse proxy stripping the response; guest login forced by an unconfigured site.","solutions":["Retry the operation after a few seconds — captcha generation can be transiently unavailable or rate-limited.","Disable login captcha in Cloudreve admin panel (Settings -> Login) if API mounting is intended, removing the dependency entirely.","Verify GET /site/captcha directly with curl/cookies to confirm the server returns a non-empty base64 image.","Upgrade the driver/repo — newer Cloudrebve builds tie captcha to a ticket; make sure your server and driver versions match."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for range 3 {\n    err = d.doLogin(true)\n    if err == nil || err.Error() != \"can not get captcha\" {\n        break\n    }\n    time.Sleep(2 * time.Second) // captcha endpoint may be transiently empty\n}","preventionTips":["Disable login captcha in Cloudrebve admin for API mounts","Avoid tight login retry loops that exhaust captcha generation","Verify /site/captcha returns a non-empty body before automating logins"],"tags":["cloudreve","captcha","login","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}