升级至KFP 2.0.1后调用客户端方法持续出现404错误求助
问题
此前使用kfp==2.0.0b12时一切正常,升级至kfp==2.0.1后,调用客户端方法(如client.list_pipelines())时持续出现404错误,错误信息如下:
kfp_server_api.exceptions.ApiException: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'x-powered-by': 'Express', 'content-security-policy': "default-src 'none'", 'x-content-type-options': 'nosniff', 'content-type': 'text/html; charset=utf-8', 'content-length': '170', 'date': 'Mon, 28 Aug 2023 23:52:33 GMT', 'x-envoy-upstream-service-time': '2', 'server': 'istio-envoy'}) HTTP response body: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot GET /pipeline/apis/v2beta1/pipelines</pre> </body> </html>
当前使用依赖版本:
kfp==2.0.1 kfp-pipeline-spec==0.2.2 kfp-server-api==2.0.1
客户端创建代码如下:
session = requests.Session() response = session.get(HOST) headers = { "Content-Type": "application/x-www-form-urlencoded", } data = {"login": USERNAME, "password": PASSWORD} session.post(response.url, headers=headers, data=data) return session.cookies.get_dict()["authservice_session"] client = Client(host=f"{HOST}/pipeline", cookies=f"authservice_session={session_cookie}", namespace=NAMESPACE) return client
除依赖版本外未做其他改动,请问问题出在哪里?
解决方案
核心原因
KFP 2.0正式版(含2.0.1)调整了API基础路径规则:
- 旧beta版本(如2.0.0b12)的API路径前缀为
/pipeline/apis/v2beta1 - 正式版将前缀简化为
/apis/v2beta1,同时客户端初始化的host参数不再需要附加/pipeline后缀
修复步骤
- 调整客户端host参数
将原代码中host=f"{HOST}/pipeline"改为host=HOST,去掉/pipeline后缀。修改后的客户端初始化代码:client = Client(host=HOST, cookies=f"authservice_session={session_cookie}", namespace=NAMESPACE) - 验证路径正确性
修改后客户端会自动请求正确路径/apis/v2beta1/pipelines,而非之前错误的/pipeline/apis/v2beta1/pipelines,可直接解决404问题。 - 版本一致性检查
确保KFP服务端版本与客户端版本保持一致(均为2.0.1),避免因版本不匹配引发的API路径差异。
内容的提问来源于stack exchange,提问作者d0m3n1
相关产品推荐
相关产品推荐

