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

Closed
opened 2026-02-21 19:04:25 -05:00 by yindo · 2 comments
Owner

Originally created by @GeorgeCaoJ on GitHub (Mar 20, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • 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

Originally created by @GeorgeCaoJ on GitHub (Mar 20, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [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](https://github.com/user-attachments/assets/1af0e1e2-4452-437e-be22-86b7281ded0d) However, when tested the same script text in debug mode through the Dify web interface, it works correctly. ![Image](https://github.com/user-attachments/assets/3a4f919c-74ff-4d88-8e90-0c2073d77679) 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_
yindo added the 🐞 bug label 2026-02-21 19:04:25 -05:00
yindo closed this issue 2026-02-21 19:04:25 -05:00
Author
Owner

@GeorgeCaoJ commented on GitHub (Mar 20, 2025):

Here is my DSL renamed by .txt
testScript.txt

@GeorgeCaoJ commented on GitHub (Mar 20, 2025): Here is my DSL renamed by .txt [testScript.txt](https://github.com/user-attachments/files/19361192/testScript.txt)
Author
Owner

@dosubot[bot] commented on GitHub (Mar 20, 2025):

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] commented on GitHub (Mar 20, 2025): <!-- Greeting --> 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! <!-- Answer --> 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: ```python 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 <sup>[[1]](https://github.com/langgenius/dify/issues/12759)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/40cd4d9e-27db-4cae-9a8b-3738da6326fa?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11859