fix: request 添加超时限制

This commit is contained in:
DLmaster361
2025-04-14 15:03:29 +08:00
parent 7e502420fa
commit 4a6f874210
7 changed files with 56 additions and 24 deletions

View File

@@ -599,7 +599,7 @@ class MaaUserConfig(QConfig):
class AppConfig(GlobalConfig): class AppConfig(GlobalConfig):
VERSION = "4.3.3.0" VERSION = "4.3.3.1"
gameid_refreshed = Signal() gameid_refreshed = Signal()
PASSWORD_refreshed = Signal() PASSWORD_refreshed = Signal()
@@ -678,7 +678,8 @@ class AppConfig(GlobalConfig):
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( 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[ gameid_infos: List[
Dict[str, Union[str, Dict[str, Union[str, int]]]] Dict[str, Union[str, Dict[str, Union[str, int]]]]

View File

@@ -28,6 +28,7 @@ v4.3
from PySide6.QtWidgets import QWidget from PySide6.QtWidgets import QWidget
from PySide6.QtCore import Signal from PySide6.QtCore import Signal
import requests import requests
import time
from loguru import logger from loguru import logger
from plyer import notification from plyer import notification
import re import re
@@ -229,25 +230,41 @@ class Notification(QWidget):
content = f"{title}\n{content}" content = f"{title}\n{content}"
data = {"msgtype": "text", "text": {"content": content}} data = {"msgtype": "text", "text": {"content": content}}
# 从远程服务器获取最新主题图像
for _ in range(3):
try:
response = requests.post( response = requests.post(
url=Config.get(Config.notify_CompanyWebHookBotUrl), url=Config.get(Config.notify_CompanyWebHookBotUrl),
json=data, json=data,
timeout=10,
) )
if response.json()["errcode"] == 0: info = response.json()
logger.info("企业微信群机器人推送通知成功") break
return True except Exception as e:
err = e
time.sleep(0.1)
else: else:
logger.info("企业微信群机器人推送通知失败") logger.error(f"推送企业微信群机器人时出错:{err}")
logger.error(response.json())
self.push_info_bar.emit( self.push_info_bar.emit(
"error", "error",
"企业微信群机器人通知推送失败", "企业微信群机器人通知推送失败",
f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}', f'使用企业微信群机器人推送通知时出错:{info["errmsg"]}',
-1, -1,
) )
return ( return None
f'使用企业微信群机器人推送通知时出错:\n{response.json()["errmsg"]}'
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): def send_test_notification(self):
"""发送测试通知到所有已启用的通知渠道""" """发送测试通知到所有已启用的通知渠道"""

View File

@@ -202,7 +202,8 @@ class Home(QWidget):
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( 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() theme_image = response.json()
break break
@@ -238,7 +239,7 @@ class Home(QWidget):
> time_local > time_local
): ):
response = requests.get(theme_image["url"]) response = requests.get(theme_image["url"], timeout=10)
if response.status_code == 200: if response.status_code == 200:
with open( with open(

View File

@@ -340,7 +340,8 @@ class MemberManager(QWidget):
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( 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() maa_info = response.json()
break break

View File

@@ -271,7 +271,8 @@ class Setting(QWidget):
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( response = requests.get(
f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaGui&current_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&current_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]]] = ( version_info: Dict[str, Union[int, str, Dict[str, str]]] = (
response.json() response.json()
@@ -417,7 +418,8 @@ class Setting(QWidget):
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( 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() notice = response.json()
break break

View File

@@ -302,7 +302,10 @@ class DownloadManager(QDialog):
elif self.config["mode"] == "MirrorChyan": elif self.config["mode"] == "MirrorChyan":
with requests.get( with requests.get(
self.config["url"], allow_redirects=True, stream=True self.config["url"],
allow_redirects=True,
timeout=10,
stream=True,
) as response: ) as response:
if response.status_code == 200: if response.status_code == 200:
return response.url return response.url
@@ -399,7 +402,7 @@ class DownloadManager(QDialog):
url = self.get_download_url("下载") url = self.get_download_url("下载")
self.downloaded_size_list: List[List[int, bool]] = [] 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)) self.file_size = int(response.headers.get("content-length", 0))
part_size = self.file_size // self.config["thread_numb"] part_size = self.file_size // self.config["thread_numb"]
@@ -661,7 +664,8 @@ if __name__ == "__main__":
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( response = requests.get(
f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaDownloader&current_version={version_text(current_version)}&cdk={mirrorchyan_CDK}&channel={update_type}" f"https://mirrorchyan.com/api/resources/AUTO_MAA/latest?user_agent=AutoMaaDownloader&current_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() version_info: Dict[str, Union[int, str, Dict[str, str]]] = response.json()
break break
@@ -696,7 +700,8 @@ if __name__ == "__main__":
for _ in range(3): for _ in range(3):
try: try:
response = requests.get( 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() download_info = response.json()

View File

@@ -1,8 +1,13 @@
{ {
"main_version": "4.3.3.0", "main_version": "4.3.3.1",
"updater_version": "1.0.0.0", "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- 公告样式优化", "announcement": "\n## 新增功能\n- 屏蔽MuMu模拟器开屏广告功能上线\n- 更新器支持多线程下载\n- 添加强制关闭ADB与模拟器等增强任务项\n## 修复BUG\n- 修复统计信息HTML模板公招匹配错误\n- 修复密码显示按钮动画异常\n- 修复`检测到MAA未能实际执行任务`报错被异常屏蔽\n- 修复MAA超时判定异常失效\n## 程序优化\n- 关机等电源操作添加100s倒计时\n- 人工排查弹窗方法优化\n- 人工排查时自动屏蔽静默操作\n- 公告样式优化",
"version_info": { "version_info": {
"4.3.3.1": {
"程序优化": [
"request 添加超时限制"
]
},
"4.3.3.0": { "4.3.3.0": {
"修复BUG": [ "修复BUG": [
"修复更新器无法下载MAA的异常" "修复更新器无法下载MAA的异常"