xpzouying/xiaohongshu-mcp · error
第%d张图片上传超时
Error message
第%d张图片上传超时
What it means
This error wraps a timeout raised by waitForUploadComplete: after submitting an image to the Xiaohongshu creator upload input, the library polls the page for .img-preview-area .pr preview elements for up to 60 seconds. If the number of preview thumbnails never reaches the expected count, the upload is considered failed and this error is returned to Publish with the 1-based image index.
Source
Thrown at xiaohongshu/publish.go:264
validPaths = append(validPaths, path)
logrus.Infof("获取有效图片:%s", path)
}
// 逐张上传:每张上传后等待预览出现,再上传下一张
for i, path := range validPaths {
uploadInput, err := findImageUploadInput(page, i == 0)
if err != nil {
return errors.Wrapf(err, "查找上传输入框失败(第%d张)", i+1)
}
if err := uploadInput.SetFiles([]string{path}); err != nil {
return errors.Wrapf(err, "上传第%d张图片失败", i+1)
}
slog.Info("图片已提交上传", "index", i+1, "path", path)
// 等待当前图片上传完成(预览元素数量达到 i+1),最多等 60 秒
if err := waitForUploadComplete(page, i+1); err != nil {
return errors.Wrapf(err, "第%d张图片上传超时", i+1)
}
time.Sleep(1 * time.Second)
}
return nil
}
// findImageUploadInput 查找图片上传的输入框
func findImageUploadInput(page *rod.Page, first bool) (*rod.Element, error) {
if first {
return page.Element(".upload-input")
}
inputs, err := page.Elements(`input[type="file"]`)
if err != nil {
return nil, err
}
if len(inputs) == 0 {View on GitHub (pinned to 332d196854)
Solutions
- Check network connectivity and upload bandwidth; retry on a stable connection
- Compress/resize images (e.g. convert HEIC to JPEG, keep under a few MB) before calling Publish
- Verify the file exists and is a supported format (the library silently skips nonexistent paths, so a wrong path can shift indexes)
- Inspect the creator page to confirm the preview selector .img-preview-area .pr still matches the current DOM; update the selector if the site changed
- Increase the 60s maxWaitTime in waitForUploadComplete if uploads are legitimately slow
Example fix
// before
images := []string{"/photos/IMG_0001.heic"}
err := bot.Publish(ctx, post, images)
// after
jpegPath, _ := convertToJPEG("/photos/IMG_0001.heic") // downscale + convert
images := []string{jpegPath}
err := bot.Publish(ctx, post, images) Defensive patterns
Strategy: validation
Validate before calling
for _, p := range images {
info, err := os.Stat(p)
if err != nil { return fmt.Errorf("图片不存在: %s", p) }
if info.Size() > 10<<20 { return fmt.Errorf("图片过大(%dMB), 请压缩: %s", info.Size()>>20, p) }
} Try / catch
err := bot.Publish(ctx, post, images)
if err != nil && strings.Contains(err.Error(), "上传超时") {
// 压缩图片后重试一次
} Prevention
- Pre-compress/convert images to JPEG/WebP under a few MB
- Pre-check file existence and size before calling Publish
- Ensure a stable network connection for uploads
- Keep the library's DOM selectors up to date with the site
When it happens
Trigger: Calling Publish with images where a submitted file never produces a preview element within 60s — e.g. waitForUploadComplete(page, i+1) returns errors.Errorf after the 60s poll loop in uploadImages (xiaohongshu/publish.go:264).
Common situations: Slow/unstable network uplink; very large images (multi-MB HEIC/raw files); Xiaohongshu page DOM changed so .img-preview-area .pr no longer matches; upload rejected server-side (bad format, quota); the browser page was closed or navigated mid-upload.
Related errors
- 第%d张图片上传超时(60s),请检查网络连接和图片大小
- 翻找 %d 轮仍未定位到评论 %s
- failed to download image from %s
- check login status failed
- read current user state failed
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/405dc931cef37ff2.
Report an issue: GitHub.