You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure ML更新现有Web服务报错:'str'对象无'id'属性AttributeError

错误根本原因

报错是因为你调用service.update()时传入的第一个参数image是字符串类型的'testazureml',而Azure ML SDK的AKS服务update方法要求该位置参数为ContainerImage类型对象,SDK源码内部会尝试读取该对象的id属性,字符串没有该属性因此触发AttributeError。同时你传入的第二个参数'image.id'是无效的多余参数,不需要传递。

修复步骤
  • 步骤1:正确获取/创建ContainerImage对象,不要直接给image变量赋值字符串
    如果你要使用已有的名为testazureml的镜像,用ContainerImage.get()方法获取:
    # 替换为你实际的镜像版本,不填默认取最新版本
    image = ContainerImage.get(workspace=ws, name='testazureml', version='<你的镜像版本号>')
    
    如果你要基于注册的模型和镜像配置构建新镜像,用ContainerImage.create()方法创建:
    image = ContainerImage.create(
        name="testazureml",
        models=[model],
        image_config=image_config,
        workspace=ws
    )
    # 等待镜像构建完成
    image.wait_for_creation(show_output=True)
    
  • 步骤2:修改service.update()调用逻辑,只传入正确的Image对象即可
    # 去掉多余的第二个字符串参数
    service.update(image=image)
    # 可选:等待更新完成验证结果
    service.wait_for_deployment(show_output=True)
    
完整修正后的参考代码
ws = Workspace.get(
        name=workspace_name,
        subscription_id=subscription_id,
        resource_group=resource_group,
        auth=cli_auth)

model = Model.register(model_path = model_path,
                   model_name = model_name,
                   description = model_description,
                   workspace = ws)

image_config = ContainerImage.image_configuration(execution_script="score.py", 
                                              runtime="python", 
                                              conda_file="packagesenv.yml")
service_name = 'testazureml'

# 正确构建镜像对象:这里以新建镜像为例,如果用已有镜像就替换为ContainerImage.get逻辑
image = ContainerImage.create(
    name="testazureml",
    models=[model],
    image_config=image_config,
    workspace=ws
)
image.wait_for_creation(show_output=True)

# Retrieve existing service
service = Webservice(name = service_name, workspace = ws)

print(service)

# 修正update调用,仅传入Image类型对象
service.update(image=image)
# 等待部署更新完成
service.wait_for_deployment(show_output=True)

内容的提问来源于stack exchange,提问作者megha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 04:57:01