1 validation error for ImageConfig image_size Extra inputs are not permitted [ty...

2025年11月25日 10:53 状态: processing

🚨 错误信息

Traceback (most recent call last): File "/Users/terminus/Documents/code/aigc/nano_banana_pro_multipic.py", line 64, in <module> image_config=types.ImageConfig( File "/Users/terminus/opt/anaconda3/lib/python3.9/site-packages/pydantic/main.py", line 250, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for ImageConfig image_size Extra inputs are not permitted [type=extra_forbidden, input_value='4K', input_type=str] For further information visit https://errors.pydantic.dev/2.12/v/..._forbidden

🤖 AI解决方案

错误翻译

原文:Extra inputs are not permitted
译文:不允许额外的输入

原因分析

  • 根本原因: 在创建 ImageConfig 对象时,传入了 image_size='4K' 参数,但该参数在 ImageConfig 模型定义中不存在或不被允许

  • 错误位置: nano_banana_pro_multipic.py 文件第64行,types.ImageConfig() 初始化时
  • 解决方案

    # 正确的写法 - 检查 ImageConfig 模型的实际字段
    image_config = types.ImageConfig(
        # 只使用模型中定义的合法字段
        # 例如可能需要使用正确的字段名,如 size 或 resolution
        size="4K"  # 或者 resolution="4K",具体取决于模型定义
    )
    
    # 或者检查模型文档,查看支持的参数

    预防措施

  • 检查模型定义: 使用 print(types.ImageConfig.__fields__) 查看模型允许的字段

  • IDE提示: 启用代码自动补全和类型提示功能,避免拼写错误或使用不存在的字段

验证步骤

# 查看 ImageConfig 模型的有效字段
print("可用字段:", list(types.ImageConfig.__fields__.keys()))

确认正确的字段名后,使用模型定义的合法参数即可解决此问题。