tool.py post multipart/form-data can not send correct Content-Type Header #11289

Closed
opened 2026-02-21 18:57:53 -05:00 by yindo · 0 comments
Owner

Originally created by @loveht on GitHub (Mar 16, 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.0.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

In tool.py, the httpx library is used to send a POST request. When posting with multipart/form-data, httpx automatically manages the Content-Type header, including both multipart/form-data and the boundary. However, on line 180 of tool.py, the code sets headers["Content-Type"] = content_type, which prevents httpx from adding the boundary. As a result, the server returns a 400 Bad Request error.

One solution is to delete the Content-Type header before sending the request, for example:
if headers.get("Content-Type") == "multipart/form-data":
del headers["Content-Type"]

✔️ Expected Behavior

No response

Actual Behavior

400 Bad Request error.

Originally created by @loveht on GitHub (Mar 16, 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.0.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce In tool.py, the httpx library is used to send a POST request. When posting with multipart/form-data, httpx automatically manages the Content-Type header, including both multipart/form-data and the boundary. However, on line 180 of tool.py, the code sets headers["Content-Type"] = content_type, which prevents httpx from adding the boundary. As a result, the server returns a 400 Bad Request error. One solution is to delete the Content-Type header before sending the request, for example: if headers.get("Content-Type") == "multipart/form-data": del headers["Content-Type"] ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior 400 Bad Request error.
yindo added the 🐞 bug label 2026-02-21 18:57:53 -05:00
yindo closed this issue 2026-02-21 18:57:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11289