for question 66f1b940f8bb4425f74e4299 with model claude-opus-4-5-20251101-thinki...

2025年12月04日 11:25 状态: processing

🚨 错误信息

Error for question 66f1b940f8bb4425f74e4299 with model claude-opus-4-5-20251101-thinking: Error code: 500 - {'error': {'message': 'InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 96616c03-d41b-45ee-9e99-38f9ee59a4ce, ValidationException: ***.***.***.***.***.***.***.data: At least one of the image dimensions exceed max allowed size: 8000 pixels (request id: 20251204111656150286285QeUPIZo1) (request id: 20251204111629483153416Fri198zg) (request id: 20251204111629352905241TqF8nDTI) (request id: 20251204111509463895911tF0OMegn)', 'type': 'rix_api_error', 'param': '', 'code': None}}, retrying... (attempt 1/3)

🤖 AI解决方案

错误翻译

原文:ValidationException: ***.***.***.***.***.***.***.data: At least one of the image dimensions exceed max allowed size: 8000 pixels
译文:验证异常:至少有一个图像尺寸超过了最大允许尺寸:8000像素

原因分析

该错误是由于上传的图像文件尺寸过大导致的。Bedrock Runtime服务对图像尺寸有严格限制,任何一边的尺寸都不能超过8000像素。

解决方案

方法1:调整图像尺寸

from PIL import Image

def resize_image(image_path, max_size=8000):
    img = Image.open(image_path)
    width, height = img.size
    
    if max(width, height) > max_size:
        # 计算缩放比例
        scale = max_size / max(width, height)
        new_width = int(width * scale)
        new_height = int(height * scale)
        
        # 调整尺寸
        img_resized = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
        img_resized.save(image_path)
        print(f"图像已从 {width}x{height} 调整为 {new_width}x{new_height}")

方法2:使用图像处理库批量处理

import cv2

def resize_image_cv2(image_path, max_dimension=8000):
    img = cv2.imread(image_path)
    height, width = img.shape[:2]
    
    if max(width, height) > max_dimension:
        scale = max_dimension / max(width, height)
        new_width = int(width * scale)
        new_height = int(height * scale)
        
        resized_img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_AREA)
        cv2.imwrite(image_path, resized_img)

️ 预防措施

  • 预处理检查:在上传图像前,自动检查图像尺寸并强制调整到允许范围内
  • 客户端验证:在前端添加图像尺寸验证,提前拦截超大图像上传
  • 使用图像压缩工具:推荐使用 ImageMagick、Pillow 等工具进行批量处理
  • 推荐工具

  • PIL/Pillow (Python图像处理库)

  • ImageMagick (命令行图像处理工具)

  • 在线图像压缩网站如 TinyPNG