From 11450af2c5ddaad2877a0dd30373c42bc5ffcab1 Mon Sep 17 00:00:00 2001 From: v_ghluguo Date: Fri, 25 Oct 2024 14:41:11 +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..3bf4496 100644 --- a/bkflow/pipeline_plugins/components/collections/http/v1_0.py +++ b/bkflow/pipeline_plugins/components/collections/http/v1_0.py @@ -24,6 +24,7 @@ import traceback from copy import deepcopy +import ujson as json from django.utils import translation from django.utils.translation import ugettext_lazy as _ from pipeline.component_framework.component import Component @@ -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"