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

Kubeflow Pipelines REST API POST请求发起Pipeline运行返回400错误问询

问题原因与解决方法

核心错误:请求参数传递方式错误

你调用requests.post时使用data参数传递JSON数据,和你指定的application/json请求头不匹配:data参数默认会将字典序列化为表单编码格式,导致Kubeflow服务端无法正确解析请求体。你看到的ListRuns must filter by resource reference报错是服务端解析失败后的误返回,本质是请求体格式不符合要求。

修复步骤

  1. 将session.post的入参从data=inputobject2修改为json=inputobject2,requests会自动将字典序列化为JSON格式并匹配请求头。
  2. (可选校验)确认$pipelineid的资源类型:
    • 如果是Pipeline版本ID,当前type: PIPELINE_VERSION配置正确
    • 如果是Pipeline主ID,将type修改为PIPELINE
  3. (多用户模式可选补充)如果修改后仍报错,可在resource_references列表中新增命名空间引用:
    {"key":{"id":"<你的Kubeflow命名空间>","type":"NAMESPACE"},"relationship":"OWNER"}
    

修正后代码示例

import requests
from pprint import pprint as pp

runURL = f"{HOST}/pipeline/apis/v1beta1/runs"
inputobject2={
    "description":"",
    "name":"gcd_test3",
    "pipeline_spec": {
        "parameters":[{"name":"a","value":"70"},{"name":"b","value":"35"},{"name":"c","value":"42"},{"name":"d","value":"14"}]
    },
    "resource_references":[
        {"key":{"id":"$experimentID","type":"EXPERIMENT"},"relationship":"OWNER"},
        {"key":{"id":"$pipelineid","type":"PIPELINE_VERSION"},"relationship":"CREATOR"}
    ],
    "service_account":""
}
headers2 = {
    "Content-Type": "application/json"
}
# 仅修改此处参数:data改为json
output = session.post(runURL, json=inputobject2, headers = headers2)
pp(output)
pp(output.json())

修改后重新请求即可正常触发Pipeline运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 03:48:03