fix: request 添加超时限制
This commit is contained in:
@@ -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]]]]
|
||||
|
||||
@@ -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):
|
||||
"""发送测试通知到所有已启用的通知渠道"""
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user