mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
fix(reports): 修复 generators.py 中 _get_user_avatar 的 TypeError。将 aiohttp 请求重构为异步上下文模式,确保 response.read() 被正确等待,并增加了网络连接失败处理
This commit is contained in:
@@ -302,12 +302,17 @@ class ReportGenerator:
|
|||||||
try:
|
try:
|
||||||
avatar_url = f"https://q4.qlogo.cn/headimg_dl?dst_uin={user_id}&spec=100"
|
avatar_url = f"https://q4.qlogo.cn/headimg_dl?dst_uin={user_id}&spec=100"
|
||||||
async with aiohttp.ClientSession() as client:
|
async with aiohttp.ClientSession() as client:
|
||||||
response = await client.get(avatar_url)
|
async with client.get(avatar_url) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
avatar_data = await response.read()
|
avatar_data = await response.read()
|
||||||
# 转换为base64编码
|
|
||||||
avatar_base64 = base64.b64encode(avatar_data).decode("utf-8")
|
if not isinstance(avatar_data, bytes):
|
||||||
return f"data:image/jpeg;base64,{avatar_base64}"
|
logger.warning(f"获取到的头像数据类型异常: {type(avatar_data)}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 转换为base64编码
|
||||||
|
avatar_base64 = base64.b64encode(avatar_data).decode("utf-8")
|
||||||
|
return f"data:image/jpeg;base64,{avatar_base64}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取用户头像失败 {user_id}: {e}")
|
logger.error(f"获取用户头像失败 {user_id}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user