From ba717f65b8520463826fd11aa2d4af19adde9913 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Fri, 25 Oct 2024 15:39:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20http=20=E6=8F=92=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20json=20=E8=BD=AC=E4=B9=89=20#40?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/collections/http/v1_0.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bkflow/pipeline_plugins/components/collections/http/v1_0.py b/bkflow/pipeline_plugins/components/collections/http/v1_0.py index be15c56..6f68d0a 100644 --- a/bkflow/pipeline_plugins/components/collections/http/v1_0.py +++ b/bkflow/pipeline_plugins/components/collections/http/v1_0.py @@ -21,6 +21,7 @@ from __future__ import absolute_import +import json import traceback from copy import deepcopy @@ -93,10 +94,7 @@ def inputs_format(self): key="bk_http_success_exp", type="string", schema=StringItemSchema( - description=_( - "根据返回的 JSON 的数据来控制节点的成功或失败, " - "使用 resp 引用返回的 JSON 对象,例 resp.result==True" - ) + description=_("根据返回的 JSON 的数据来控制节点的成功或失败, " "使用 resp 引用返回的 JSON 对象,例 resp.result==True") ), ), ] @@ -133,6 +131,8 @@ def plugin_schedule(self, data, parent_data, callback_data=None): other = {"headers": {}, "timeout": timeout} if method.upper() not in ["GET", "HEAD"]: + if not isinstance(body, str): + body = json.dumps(body) other["data"] = body.encode("utf-8") other["headers"] = {"Content-type": "application/json"} @@ -195,10 +195,7 @@ def __getstate__(self): class HttpComponent(Component): name = _("HTTP 请求") - desc = _( - "提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " - "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功" - ) + desc = _("提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功") code = "bk_http_request" bound_service = HttpRequestService version = "v1.0"