mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-07 01:46:49 +08:00
fix(http_request): simplify JSON handling in requests (#9616)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from collections.abc import Mapping, Sequence
|
||||
from collections.abc import Mapping
|
||||
from copy import deepcopy
|
||||
from random import randint
|
||||
from typing import Any, Literal
|
||||
@@ -60,7 +60,7 @@ class Executor:
|
||||
self.method = node_data.method
|
||||
self.auth = node_data.authorization
|
||||
self.timeout = timeout
|
||||
self.params = None
|
||||
self.params = {}
|
||||
self.headers = {}
|
||||
self.content = None
|
||||
self.files = None
|
||||
@@ -108,8 +108,10 @@ class Executor:
|
||||
case "raw-text":
|
||||
self.content = self.variable_pool.convert_template(data[0].value).text
|
||||
case "json":
|
||||
json_object = json.loads(data[0].value)
|
||||
self.json = self._parse_object_contains_variables(json_object)
|
||||
json_string = self.variable_pool.convert_template(data[0].value).text
|
||||
json_object = json.loads(json_string)
|
||||
self.json = json_object
|
||||
# self.json = self._parse_object_contains_variables(json_object)
|
||||
case "binary":
|
||||
file_selector = data[0].file
|
||||
file_variable = self.variable_pool.get_file(file_selector)
|
||||
@@ -274,14 +276,6 @@ class Executor:
|
||||
|
||||
return raw
|
||||
|
||||
def _parse_object_contains_variables(self, obj: str | dict | list, /) -> Mapping[str, Any] | Sequence[Any] | str:
|
||||
if isinstance(obj, dict):
|
||||
return {k: self._parse_object_contains_variables(v) for k, v in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
return [self._parse_object_contains_variables(v) for v in obj]
|
||||
elif isinstance(obj, str):
|
||||
return self.variable_pool.convert_template(obj).text
|
||||
|
||||
|
||||
def _plain_text_to_dict(text: str, /) -> dict[str, str]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user