
WaterCrawl client rejects JSON responses with Content-Type parameters
快速结论:此报错发生在 Dify 使用 WaterCrawl 数据源(datasource)时,因为 WaterCrawl 客户端的 process_response() 方法对 Content-Type 头使用严格字符串相等比较,当返回的 JSON 响应带有 charset=utf-8 等参数时(例如 application/json; charset=utf-8),会被错误地视为未知响应类型。优先排查 WaterCrawl 返回的 Content-Type 是否包含参数。
问题场景
在 Dify 中使用 WaterCrawl 数据源(datasource path)时,当 WaterCrawl 服务或中间代理返回的 HTTP 响应中,Content-Type 头为带参数的 JSON 类型(如 application/json; charset=utf-8),将触发此异常。
报错原文
Unknown response type: application/json; charset=utf-8
原因分析
根本原因是在 api/core/rag/extractor/watercrawl/client.py 文件的 process_response() 方法中,对所有三种 Content-Type 检查(application/json、application/octet-stream、text/event-stream)使用了严格字符串相等比较:
if response.headers.get("Content-Type") == "application/json":
任何带参数的 Content-Type 头(如 application/json; charset=utf-8)都无法匹配,从而导致程序 fall through 到 Unknown response type 异常。这是一个符合 HTTP 规范的 media type 解析缺陷。
环境排查
- 触发问题的 Dify 版本:main branch commit
b6b9165d(fix(agent): include app display fields in published references (#37485)) - 受影响的文件:
api/core/rag/extractor/watercrawl/client.py(第 121-128 行) - 运行模式:Cloud 或 Self Hosted(Source)均可触发
解决步骤
- 打开文件
api/core/rag/extractor/watercrawl/client.py。 - 找到
process_response()方法中所有Content-Type比较的代码行。 - 将原本的严格相等比较,改为先按分号(
;)分割以去除媒体类型参数,再去掉首尾空格后再进行比较。具体修改为:
content_type = response.headers.get("Content-Type", "").split(";")[0].strip() if content_type == "application/json": return response.json() or {} if content_type == "application/octet-stream": return response.content if content_type == "text/event-stream": return self.process_eventstream(response) raise Exception(f"Unknown response type: {response.headers.get('Content-Type')}") - 保存文件并重启 Dify 服务。
验证方法
重新触发之前失败的 WaterCrawl 数据源请求,确认不再抛出 Unknown response type 异常,并且能够正常解析返回的 JSON 数据。



