【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()}")
相关推荐
-拟墨画扇-2 小时前
Git | Bug分支操作
git·gitee·github·bug·gitcode
小凡子空白在线学习3 小时前
Bug目录
bug
jiedaodezhuti1 天前
秒级定位线上Bug的一些命令
bug
l1t3 天前
修改一个触发PostgreSQL 17.2 bug的SQL
sql·postgresql·bug
包小黑3 天前
【Linux】bug登记好习惯:发现bug,用命令行截取对应日志
linux·bug
癫狂的兔子5 天前
【BUG】【Python】逆序取值为空
bug
癫狂的兔子5 天前
【BUG】【Python】精确度问题
python·bug
癫狂的兔子5 天前
【BUG】【Python】合并两个列表
bug
癫狂的兔子5 天前
【BUG】【Python】eval()报错
python·bug
余生H5 天前
Ai编程翻车修车记3 -一次因为移除监听器失败导致bug后的DOM事件深入学习
学习·bug·ai编程