{"record":{"id":"9f4d1601b8f624b2","repo":"AlistGo/alist","slug":"not-found-302-redirect","errorCode":null,"errorMessage":"not found 302 redirect","messagePattern":"not found 302 redirect","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/baidu_photo/utils.go","lineNumber":360,"sourceCode":"\t}\n\n\tresp, err := d.Request(base.NoRedirectClient, ALBUM_API_URL+\"/download\", http.MethodHead, func(r *resty.Request) {\n\t\tr.SetContext(ctx)\n\t\tr.SetHeaders(headers)\n\t\tr.SetQueryParams(map[string]string{\n\t\t\t\"fsid\":     fmt.Sprint(file.Fsid),\n\t\t\t\"album_id\": file.AlbumID,\n\t\t\t\"tid\":      fmt.Sprint(file.Tid),\n\t\t\t\"uk\":       fmt.Sprint(file.Uk),\n\t\t})\n\t}, nil)\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif resp.StatusCode() != 302 {\n\t\treturn nil, fmt.Errorf(\"not found 302 redirect\")\n\t}\n\n\tlocation := resp.Header().Get(\"Location\")\n\n\tlink := &model.Link{\n\t\tURL: location,\n\t\tHeader: http.Header{\n\t\t\t\"User-Agent\": []string{headers[\"User-Agent\"]},\n\t\t\t\"Referer\":    []string{\"https://photo.baidu.com/\"},\n\t\t},\n\t}\n\treturn link, nil\n}\n\nfunc (d *BaiduPhoto) linkFile(ctx context.Context, file *File, args model.LinkArgs) (*model.Link, error) {\n\theaders := map[string]string{\n\t\t\"User-Agent\": base.UserAgent,\n\t}","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/baidu_photo/utils.go#L342-L378","documentation":"Thrown by BaiduPhoto.linkAlbum (drivers/baidu_photo/utils.go:360) when the download-request endpoint for an album file does not answer with HTTP 302. The driver expects the server to redirect to the real file URL and reads the Location header to build model.Link; any other status (200 with an error page, 4xx/5xx) means no download link was issued.","triggerScenarios":"Calling Link on an AlbumFile whose download request returns non-302: expired or invalid cookies/token for the album owner, the file was removed from the album, or Baidu served an anti-bot/validation page instead of the redirect.","commonSituations":"Playing album files after the session cookies went stale; fetching links for files deleted since the last list; aggressive polling causing Baidu to drop the redirect.","solutions":["Re-init/refresh the driver credentials (cookies/access_token) and retry Link once","Re-list the album and confirm the file still exists before linking","Check errno in the response body of the failed request to distinguish auth vs missing-file"],"exampleFix":"// before\nif resp.StatusCode() != 302 {\n    return nil, fmt.Errorf(\"not found 302 redirect\")\n}\n\n// after\nif resp.StatusCode() != 302 {\n    if utils.Json.Get(resp.Body(), \"errno\").ToInt() == -6 {\n        return nil, errs.NewErr(errs.TokenExpired, \"album link: session expired, status %d\", resp.StatusCode())\n    }\n    return nil, fmt.Errorf(\"not found 302 redirect, got status %d body %s\", resp.StatusCode(), resp.Body())\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"link, err := d.linkAlbum(ctx, file, args)\nif err != nil && strings.Contains(err.Error(), \"not found 302 redirect\") {\n    if ierr := d.Init(ctx); ierr == nil { // refresh cookies/session\n        link, err = d.linkAlbum(ctx, file, args)\n    }\n}\nif err != nil {\n    return nil, err\n}","preventionTips":["Re-list the album before linking to confirm the file still exists","Keep driver sessions warm: re-init on schedule rather than waiting for link failures","Cap retries at one — a second non-302 usually means the file is gone, not a transient fault"],"tags":["baidu-photo","download","http","auth"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}