【BUG】流式响应requests得到: ping - 和时间戳

前情提要

运行Langchain-Chatchat项目,使用自定义请求访问API Server流式输出

报错展示

bash 复制代码
b': ping - 2024-05-22 00:46:04.832520+00:00\r\n\r\n'

报错原因

这通常是由于 Server-Sent Events (SSE) 实现中使用的"心跳"机制,以确保连接保持活跃。一些 SSE 实现会定期发送 ping 消息,以防止连接超时或被关闭。

解决方案

1、降低sse_starlette版本为1.8.2

我之前用的是2.1.0,不想降低版本用第二个方法

2、EventSourceResponse函数中注释304~311行

bash 复制代码
            if self.ping_message_factory:
                assert isinstance(self.ping_message_factory, Callable)  # type: ignore  # https://github.com/python/mypy/issues/6864
            ping = (
                ServerSentEvent(comment=f"ping - {datetime.utcnow()}").encode()
                if self.ping_message_factory is None
                else ensure_bytes(self.ping_message_factory(), self.sep)
            )
            _log.debug(f"ping: {ping.decode()}")
相关推荐
烧烧的酒0.o3 天前
Codex桌面版更新后不能使用最新模型问题-排查修复总结
chatgpt·bug
sg_knight4 天前
ZCode Bug 定位实战:把报错丢给 ZCode,它是怎么修的
llm·bug·agent·ai编程·glm·智谱·zcode
轩轶子6 天前
Python CLI Todo:一次数据结构错误引发的 Bug
数据结构·python·bug
鬼手点金6 天前
Claude Code示范案例-修复 Bug 工作流
java·服务器·前端·javascript·bug·openclaw
^Rocky14 天前
IT 疑难杂症诊疗室:复杂技术问题解决实录
运维·bug
Keven_1116 天前
Bug:UVA816
bug
Keven_1116 天前
Bug:UVA1103
bug
钱栈up17 天前
坯料管理导入功能bug修复:只改前端一个文件就解决问题
前端·bug
项目管理实用笔记17 天前
Bug跟踪管理系统有哪些?2026 推荐清单与选型指南
bug·研发管理·研发管理工具·项目管理软件选型
iNeuOS工业互联网20 天前
iNeuOS工业互联网操作系统,重要更新:性能优化、安全漏洞与BUG修复,远程控制响应效率大幅提升
性能优化·bug