minor change
This commit is contained in:
@@ -97,7 +97,7 @@ def apiSDGB(
|
||||
requestDataFinal = aes.encrypt(zlib.compress(data.encode('utf-8')))
|
||||
|
||||
if not noLog:
|
||||
logger.debug(f"开始请求 {targetApi},以 {data}")
|
||||
logger.debug(f"[Stage 1] 准备开始请求 {targetApi},以 {data}")
|
||||
|
||||
retries = 0
|
||||
while retries < maxRetries:
|
||||
@@ -126,10 +126,10 @@ def apiSDGB(
|
||||
)
|
||||
|
||||
if not noLog:
|
||||
logger.info(f"{targetApi} 请求结果: {response.status_code}")
|
||||
logger.info(f"[Stage 2] {targetApi} 请求结果: {response.status_code}")
|
||||
|
||||
if response.status_code != 200:
|
||||
errorMessage = f"请求失败: {response.status_code}"
|
||||
errorMessage = f"[Stage 2] 请求失败: {response.status_code}"
|
||||
logger.error(errorMessage)
|
||||
raise SDGBRequestError(errorMessage)
|
||||
|
||||
@@ -140,28 +140,30 @@ def apiSDGB(
|
||||
try:
|
||||
responseContentDecrypted = aes.decrypt(responseContentRaw)
|
||||
if not noLog:
|
||||
logger.debug("成功解密响应!")
|
||||
logger.debug("[Stage 3] Decryption SUCCESS.")
|
||||
except Exception as e:
|
||||
logger.warning(f"解密失败,原始响应: {responseContentRaw}, 错误: {e}")
|
||||
raise SDGBResponseError("解密失败")
|
||||
logger.warning(f"[Stage 3] Decryption FAILED. Raw Content: {responseContentRaw}, Error: {e}")
|
||||
raise SDGBResponseError("Decryption failed")
|
||||
# 然后尝试解压
|
||||
try:
|
||||
# 看看文件头是否是压缩过的
|
||||
if responseContentDecrypted.startswith(b'\x78\x9c'):
|
||||
logger.debug("响应内容是 zlib 压缩格式")
|
||||
logger.debug("[Stage 4] Zlib detected, decompressing...")
|
||||
responseContentFinal = zlib.decompress(responseContentDecrypted).decode('utf-8')
|
||||
else:
|
||||
logger.warning(f"响应内容不是 zlib 压缩格式, 内容: {responseContentDecrypted}")
|
||||
logger.warning(f"[Stage 4] Not Zlib Format!! using raw content: {responseContentDecrypted}")
|
||||
responseContentFinal = responseContentDecrypted.decode('utf-8')
|
||||
# 完成解压
|
||||
if not noLog:
|
||||
logger.debug(f"响应: {responseContentFinal}")
|
||||
logger.debug(f"[Stage 4] Process OK, Content: {responseContentFinal}")
|
||||
# 最终处理,检查是否是 JSON 格式
|
||||
if responseContentFinal.startswith('{') and responseContentFinal.endswith('}'):
|
||||
# 如果是 JSON 格式,直接返回
|
||||
logger.debug("[Stage 5] Response is JSON, returning.")
|
||||
return responseContentFinal
|
||||
else:
|
||||
# 如果不是 JSON 格式,可能是文本或其他格式,直接返回
|
||||
logger.warning("响应内容不对劲!可能有错误!")
|
||||
# 如果不是 JSON 格式,直接返回但是警告
|
||||
logger.warning("[Stage 5] Response is not JSON, returning as is, take care!")
|
||||
return responseContentFinal
|
||||
except:
|
||||
logger.warning(f"解压失败,原始响应: {responseContentDecrypted}")
|
||||
|
||||
Reference in New Issue
Block a user