Fix an unhandled exception caused by network

Signed-off-by: zlaazlaa <2889827787@qq.com>
This commit is contained in:
zlaazlaa 2024-09-11 23:50:26 +08:00
parent 8a44c17276
commit f730ae4d8b

View File

@ -84,13 +84,23 @@ def get_message_count():
total = upper_bound // 2 # 初始的总量为上下界的中间值
with tqdm(desc="正在获取消息列表数量...") as pbar:
while lower_bound <= upper_bound:
try:
response = get_message(total, 100)
if response and hasattr(response, 'text'):
if "li" in response.text:
# 请求成功,总量应该在当前总量的右侧
lower_bound = total + 1
else:
# 请求失败,总量应该在当前总量的左侧
upper_bound = total - 1
total = (lower_bound + upper_bound) // 2 # 更新总量为新的中间值
else:
print(f"无效的响应对象: {response}")
break
except Exception as e:
print(f"请求发生异常: {e}")
break
total = (lower_bound + upper_bound) // 2
pbar.update(1)
return total