由于easywechat默认文件缓存,而项目又分为了前后端2个目录,所以导致了缓存获取access_token失效的问题。(如后台更新了token,这时前台的token就会失效,反之亦然)缓存 | EasyWeChat
40001:缓存在不同的目录文件。导致互相踢出了access_token,即过期了。
解决方法:缓存放到同一个redis中读取
$app = Factory::openPlatform($config)->officialAccount($appid, $refresh_token);
// 替换应用中的缓存
$app->rebind('cache', self::$cache);
500:查日志发现循环调用数据库导致连接异常
把数据从for循环中拿到外面读取
if toc:
ids = getData(db, ids)
else:
ids = getIds(db,ids,app_id)
return StreamingResponse(konwledge_chat(ids),media_type="text/event-stream")
request数据:
async def konwledge_base_chat(request: Request):
nest_asyncio.apply()
try:
data = await request.json() # 所有参数(json)
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format in the request body")
data = await request.json()
toc = data.get("toc", 0)