dify icon indicating copy to clipboard operation
dify copied to clipboard

The HTTP request node has JSON parsing errors when executed through the workflow api, but ok in the Dify web

Open GeorgeCaoJ opened this issue 1 year ago • 2 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.1.0&0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

The HTTP request node sends a POST request containing a JSON payload with a Python script in a workflow. However, I'm getting different results when testing in the Dify web interface debug mode versus when running through the workflow API.

When executed through the workflow API, I receive an error Image

However, when tested the same script text in debug mode through the Dify web interface, it works correctly. Image

cURL: curl --location 'http://10.19.150.127:8828/v1/workflows/run'
--header 'Authorization: Bearer app-uM1zZAIJWOcaqLD8O0A7l1oP'
--header 'Content-Type: application/json'
--data '{ "inputs": { "script": "import random\nimport string\nimport time\n\ndef generate_random_token(length=32):\n """\n 生成一个指定长度的随机token\n \n 参数:\n length: token的长度,默认为32\n \n 返回:\n 随机生成的token字符串\n """\n # 定义可用于生成token的字符集\n characters = string.ascii_letters + string.digits\n \n # 生成随机token\n token = ''''''.join(random.choice(characters) for _ in range(length))\n \n # 添加时间戳使token更加唯一\n timestamp = str(int(time.time()))\n \n # 将时间戳与随机字符串组合\n final_token = token + "_" + timestamp\n \n return final_token\n\n# 示例:生成一个随机token并打印\nif name == "main":\n token = generate_random_token()\n print(token)\n", "mode": ["test"](

url

) }, "response_mode": "streaming", "user": "abc-123" }'

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

GeorgeCaoJ avatar Mar 20 '25 07:03 GeorgeCaoJ

Here is my DSL renamed by .txt testScript.txt

GeorgeCaoJ avatar Mar 20 '25 07:03 GeorgeCaoJ

Hey @GeorgeCaoJ! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's squash those bugs together!

The issue you're experiencing with JSON parsing errors when executing the HTTP request node through the workflow API, but not in the Dify web interface debug mode, might be related to how JSON strings are handled. A similar issue was resolved by ensuring that JSON strings use double quotes instead of single quotes, which are not valid in JSON. You can modify the code in /api/core/workflow/nodes/http_request/executor.py to replace single quotes with double quotes:

json_object = json.loads(json_string.replace("'", '"'), strict=False)

This change ensures that the JSON string is correctly formatted with double quotes, which is required for JSON parsing. The Dify web interface debug mode might automatically handle or correct such formatting issues, which is why the error doesn't appear there [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Mar 20 '25 08:03 dosubot[bot]