From 00776f330d565ace3a97505cb9964fb104127e5d Mon Sep 17 00:00:00 2001 From: Remik1r3n Date: Sat, 24 May 2025 11:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=20requirements.txt=EF=BC=8CT?= =?UTF-8?q?itleServer=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AEHttp=E4=BB=A3?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_TitleServer.py | 23 ++++++++++++++++------- Config.py | 3 +++ requirements.txt | 7 +++++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 requirements.txt diff --git a/API_TitleServer.py b/API_TitleServer.py index 7186b60..ec296c1 100644 --- a/API_TitleServer.py +++ b/API_TitleServer.py @@ -75,7 +75,15 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t retries = 0 while retries < maxRetries: try: - response = httpx.post( + if useProxy: + # 使用代理 + logger.debug("使用代理") + httpClient = httpx.Client(proxy=proxyUrl, verify=False) + else: + # 不使用代理 + logger.debug("不使用代理") + httpClient = httpx.Client(verify=False) + responseOriginal = httpClient.post( url=endpoint + getSDGBApiHash(targetApi), headers={ "User-Agent": f"{getSDGBApiHash(targetApi)}#{agentExtra}", @@ -89,20 +97,21 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t content=reqData_deflated, # 经测试,加 Verify 之后速度慢好多,因此建议选择性开 #verify=certifi.where(), - verify=False, + #verify=False, timeout=timeout ) - if not noLog: - logger.info(f"{targetApi} 请求结果: {response.status_code}") - if response.status_code == 200: + if not noLog: + logger.info(f"{targetApi} 请求结果: {responseOriginal.status_code}") + + if responseOriginal.status_code == 200: logger.debug("200 OK!") else: - errorMessage = f"请求失败: {response.status_code}" + errorMessage = f"请求失败: {responseOriginal.status_code}" logger.error(errorMessage) raise SDGBRequestError(errorMessage) - responseRAWContent = response.content + responseRAWContent = responseOriginal.content try: responseDecompressed = zlib.decompress(responseRAWContent) diff --git a/Config.py b/Config.py index f4e779e..c809844 100644 --- a/Config.py +++ b/Config.py @@ -4,6 +4,9 @@ placeId = 3490 placeName = "赛博时空枣庄市中店" clientId = "A63E01E9564" +useProxy = True +proxyUrl = "http://100.104.133.113:33080" + loginBonusDBPath = "./Data/loginBonusDB.json" musicDBPath = "./Data/musicDB.json" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d894623 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +pycryptodome +requests +httpx +python-rapidjson +pytz +loguru +datetime