【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()}")
相关推荐
万粉变现经纪人5 小时前
Python系列Bug修复PyCharm控制台pip install报错:如何解决 pip install 网络报错 企业网关拦截 User-Agent 问题
网络·python·pycharm·beautifulsoup·bug·pandas·pip
燕双嘤5 小时前
Bug:Nginx 转发末尾斜杠导致 404 问题分析
bug
TeleostNaCl5 小时前
一种解决 Win10的微软输入法无法禁用 shift + 空格 切换半角/全角切换bug的方法
经验分享·微软·bug
wy31362282118 小时前
android——开发中的常见Bug汇总与解决方案(闪退)
android·bug
Swift社区2 天前
RN 项目中“页面存在 ≠ 页面可见”会导致哪些隐藏 Bug?
react native·bug·react
tongyue2 天前
天问esp32驱动DHT11官方程序BUG修复
bug
laocooon5238578863 天前
写代码 调bug相关信息
bug
鸿儒5173 天前
记录一个C++操作8位影像的一个bug
开发语言·c++·bug
·云扬·3 天前
【Bug】 Elasticsearch启动失败(exit code 78):2个bootstrap检查问题排查与解决
elasticsearch·bootstrap·bug
BrianGriffin4 天前
get_download_file_path: command not found (asdf bug已解决)
bug