{"record":{"id":"883a6cb6f56ee0d6","repo":"AlistGo/alist","slug":"ocr-error-jsoniter-get-vres-body-msg-tos-883a6c","errorCode":null,"errorMessage":"ocr error:\" + jsoniter.Get(vRes.Body(), \"msg\").ToString()","messagePattern":"ocr error:\" \\+ jsoniter\\.Get\\(vRes\\.Body\\(\\), \"msg\"\\)\\.ToString\\(\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/cloudreve_v4/util.go","lineNumber":157,"sourceCode":"\t\tvar captcha CaptchaResp\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 !strings.HasPrefix(captcha.Image, \"data:image/png;base64,\") {\n\t\t\treturn errors.New(\"can not get captcha\")\n\t\t}\n\t\tloginBody[\"ticket\"] = captcha.Ticket\n\t\ti := strings.Index(captcha.Image, \",\")\n\t\tdec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(captcha.Image[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\tif captchaCode == \"\" {\n\t\t\treturn errors.New(\"ocr error: empty result\")\n\t\t}\n\t\tloginBody[\"captcha\"] = captchaCode\n\t}\n\tvar token TokenResponse\n\terr = d.request(http.MethodPost, \"/session/token\", func(req *resty.Request) {\n\t\treq.SetBody(loginBody)\n\t}, &token)\n\tif err != nil {\n\t\treturn err\n\t}\n\td.AccessToken, d.RefreshToken = token.Token.AccessToken, token.Token.RefreshToken\n\top.MustSaveDriverStorage(d)\n\treturn nil\n}","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/cloudreve_v4/util.go#L139-L175","documentation":"CloudreveV4 login forwarded the captcha PNG to the configured OCR service (conf.OcrApi multipart field 'image') and the service answered with a non-200 status in its JSON body; its msg is appended, e.g. 'ocr error:internal error'. Identical pattern to the V3 driver's OCR failure.","triggerScenarios":"Captcha enabled + OCR POST to setting.GetStr(conf.OcrApi); response body's status field != 200. Triggered by missing/wrong OcrApi setting, dead OCR service, HTML proxy error page (status parses to 0), or OCR decode failure.","commonSituations":"OcrApi never configured after enabling captcha; ddddocr container down; URL typo; service expecting a different multipart field name; network egress blocked from the alist host.","solutions":["Configure OcrApi to a reachable OCR service and test it manually with a multipart PNG upload.","Read the OCR service's msg in the error to pinpoint its failure.","Disable captcha on the V4 site to remove the dependency.","Ensure network/DNS from the alist host to the OCR service works."],"exampleFix":"curl -sS -F 'image=@validateCode.png;type=image/png' http://127.0.0.1:9898\n# {\"status\":200,\"result\":\"ab12\"}  -> OCR service healthy; set this URL as OcrApi","handlingStrategy":"validation","validationCode":"if setting.GetStr(conf.OcrApi) == \"\" { return errors.New(\"configure OcrApi before enabling captcha login\") }\nif _, err := http.Head(setting.GetStr(conf.OcrApi)); err != nil { return errors.New(\"OCR service unreachable\") }","typeGuard":"func isOcrError(err error) bool { return err != nil && strings.HasPrefix(err.Error(), \"ocr error:\") }","tryCatchPattern":"if err != nil {\n    if strings.HasPrefix(err.Error(), \"ocr error:\") {\n        return fmt.Errorf(\"captcha OCR failed (%s) — fix/disable OcrApi or turn off captcha\", err)\n    }\n    return err\n}","preventionTips":["Deploy a tested OCR service before enabling captcha","Log the OCR service msg to catch config drift","Prefer disabling captcha for API-driven logins"],"tags":["cloudreve-v4","ocr","captcha","configuration","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}