From 4a6f8742106f5385e1e4721bfade0a0b1daadc1b Mon Sep 17 00:00:00 2001 From: DLmaster361 Date: Mon, 14 Apr 2025 15:03:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20request=20=E6=B7=BB=E5=8A=A0=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 5 +++-- app/services/notification.py | 41 +++++++++++++++++++++++++----------- app/ui/home.py | 5 +++-- app/ui/member_manager.py | 3 ++- app/ui/setting.py | 6 ++++-- app/utils/downloader.py | 13 ++++++++---- resources/version.json | 7 +++++- 7 files changed, 56 insertions(+), 24 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 988f3ef..57e8394 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -599,7 +599,7 @@ class MaaUserConfig(QConfig): class AppConfig(GlobalConfig): - VERSION = "4.3.3.0" + VERSION = "4.3.3.1" gameid_refreshed = Signal() PASSWORD_refreshed = Signal() @@ -678,7 +678,8 @@ class AppConfig(GlobalConfig): for _ in range(3): try: response = requests.get( - "https://ota.maa.plus/MaaAssistantArknights/api/gui/StageActivity.json" + "https://ota.maa.plus/MaaAssistantArknights/api/gui/StageActivity.json", + timeout=10, ) gameid_infos: List[ Dict[str, Union[str, Dict[str, Union[str, int]]]] diff --git a/app/services/notification.py b/app/services/notification.py index 915f237..62f983a 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -28,6 +28,7 @@ v4.3 from PySide6.QtWidgets import QWidget from PySide6.QtCore import Signal import requests +import time from loguru import logger from plyer import notification import re @@ -229,25 +230,41 @@ class Notification(QWidget): content = f"{title}\n{content}" data = {"msgtype": "text", "text": {"content": content}} - response = requests.post( - url=Config.get(Config.notify_CompanyWebHookBotUrl), - json=data, - ) - if response.json()["errcode"] == 0: - logger.info("企业微信群机器人推送通知成功") - return True + # 从远程服务器获取最新主题图像 + for _ in range(3): + try: + response = requests.post( + url=Config.get(Config.notify_CompanyWebHookBotUrl), + json=data, + timeout=10, + ) + info = response.json() + break + except Exception as e: + err = e + time.sleep(0.1) else: - logger.info("企业微信群机器人推送通知失败") - logger.error(response.json()) + logger.error(f"推送企业微信群机器人时出错:{err}") self.push_info_bar.emit( "error", "企业微信群机器人通知推送失败", - f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}', + f'使用企业微信群机器人推送通知时出错:{info["errmsg"]}', -1, ) - return ( - f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}' + return None + + if info["errcode"] == 0: + logger.info("企业微信群机器人推送通知成功") + return True + else: + logger.error(f"企业微信群机器人推送通知失败:{info}") + self.push_info_bar.emit( + "error", + "企业微信群机器人通知推送失败", + f'使用企业微信群机器人推送通知时出错:{info["errmsg"]}', + -1, ) + return f'使用企业微信群机器人推送通知时出错:{info["errmsg"]}' def send_test_notification(self): """发送测试通知到所有已启用的通知渠道""" diff --git a/app/ui/home.py b/app/ui/home.py index cbfb11a..783cae3 100644 --- a/app/ui/home.py +++ b/app/ui/home.py @@ -202,7 +202,8 @@ class Home(QWidget): for _ in range(3): try: response = requests.get( - "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/theme_image.json" + "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/theme_image.json", + timeout=10, ) theme_image = response.json() break @@ -238,7 +239,7 @@ class Home(QWidget): > time_local ): - response = requests.get(theme_image["url"]) + response = requests.get(theme_image["url"], timeout=10) if response.status_code == 200: with open( diff --git a/app/ui/member_manager.py b/app/ui/member_manager.py index a0234a1..65b77fa 100644 --- a/app/ui/member_manager.py +++ b/app/ui/member_manager.py @@ -340,7 +340,8 @@ class MemberManager(QWidget): for _ in range(3): try: response = requests.get( - "https://mirrorchyan.com/api/resources/MAA/latest?user_agent=AutoMaaGui&os=win&arch=x64&channel=stable" + "https://mirrorchyan.com/api/resources/MAA/latest?user_agent=AutoMaaGui&os=win&arch=x64&channel=stable", + timeout=10, ) maa_info = response.json() break diff --git a/app/ui/setting.py b/app/ui/setting.py index b8cddf6..5b6ba60 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -271,7 +271,8 @@ class Setting(QWidget): for _ in range(3): try: response = requests.get( - f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaGui¤t_version={version_text(current_version)}&cdk={Crypto.win_decryptor(Config.get(Config.update_MirrorChyanCDK))}&channel={Config.get(Config.update_UpdateType)}" + f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaGui¤t_version={version_text(current_version)}&cdk={Crypto.win_decryptor(Config.get(Config.update_MirrorChyanCDK))}&channel={Config.get(Config.update_UpdateType)}", + timeout=10, ) version_info: Dict[str, Union[int, str, Dict[str, str]]] = ( response.json() @@ -417,7 +418,8 @@ class Setting(QWidget): for _ in range(3): try: response = requests.get( - "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/notice.json" + "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/notice.json", + timeout=10, ) notice = response.json() break diff --git a/app/utils/downloader.py b/app/utils/downloader.py index 0a8b126..7cde9a9 100644 --- a/app/utils/downloader.py +++ b/app/utils/downloader.py @@ -302,7 +302,10 @@ class DownloadManager(QDialog): elif self.config["mode"] == "MirrorChyan": with requests.get( - self.config["url"], allow_redirects=True, stream=True + self.config["url"], + allow_redirects=True, + timeout=10, + stream=True, ) as response: if response.status_code == 200: return response.url @@ -399,7 +402,7 @@ class DownloadManager(QDialog): url = self.get_download_url("下载") self.downloaded_size_list: List[List[int, bool]] = [] - response = requests.head(url) + response = requests.head(url, timeout=10) self.file_size = int(response.headers.get("content-length", 0)) part_size = self.file_size // self.config["thread_numb"] @@ -661,7 +664,8 @@ if __name__ == "__main__": for _ in range(3): try: response = requests.get( - f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaDownloader¤t_version={version_text(current_version)}&cdk={mirrorchyan_CDK}&channel={update_type}" + f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaDownloader¤t_version={version_text(current_version)}&cdk={mirrorchyan_CDK}&channel={update_type}", + timeout=10, ) version_info: Dict[str, Union[int, str, Dict[str, str]]] = response.json() break @@ -696,7 +700,8 @@ if __name__ == "__main__": for _ in range(3): try: response = requests.get( - "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/download_info.json" + "https://gitee.com/DLmaster_361/AUTO_MAA/raw/server/download_info.json", + timeout=10, ) download_info = response.json() diff --git a/resources/version.json b/resources/version.json index a203f90..6efddc7 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,8 +1,13 @@ { - "main_version": "4.3.3.0", + "main_version": "4.3.3.1", "updater_version": "1.0.0.0", "announcement": "\n## 新增功能\n- 屏蔽MuMu模拟器开屏广告功能上线\n- 更新器支持多线程下载\n- 添加强制关闭ADB与模拟器等增强任务项\n## 修复BUG\n- 修复统计信息HTML模板公招匹配错误\n- 修复密码显示按钮动画异常\n- 修复`检测到MAA未能实际执行任务`报错被异常屏蔽\n- 修复MAA超时判定异常失效\n## 程序优化\n- 关机等电源操作添加100s倒计时\n- 人工排查弹窗方法优化\n- 人工排查时自动屏蔽静默操作\n- 公告样式优化", "version_info": { + "4.3.3.1": { + "程序优化": [ + "request 添加超时限制" + ] + }, "4.3.3.0": { "修复BUG": [ "修复更新器无法下载MAA的异常"