feat:重试和失败均通知前端

This commit is contained in:
zcr
2025-12-24 11:30:11 +08:00
parent 7a1496aeb7
commit 8ccf899441
5 changed files with 38 additions and 16 deletions

View File

@@ -4,18 +4,24 @@ import time
import requests
def post_request(url, data=None, json_data=None, headers=None, auth=None, timeout=5):
def post_request(url, data=None, json_data=None, auth=None, timeout=5):
"""
发送POST请求的封装函数
:param url: 接口的URL地址
:param data: 要发送的数据(字典形式,用于表单数据等,会自动编码)
:param json_data: 要发送的JSON数据字典形式会自动转换为JSON字符串
:param headers: 请求头字典
:param auth: 认证信息(如 ('username', 'password') 形式用于基本认证)
:param timeout: 超时时间,单位为秒
:return: 返回接口的响应对象
"""
headers = {
'Accept': "*/*",
'Accept-Encoding': "gzip, deflate, br",
'User-Agent': "PostmanRuntime-ApipostRuntime/1.1.0",
'Connection': "keep-alive",
'Content-Type': "application/json"
}
try:
response = requests.post(
url,
@@ -52,6 +58,6 @@ if __name__ == '__main__':
'Content-Type': "application/json"
}
start_time = time.time()
X = post_request(url=url, data=json.dumps(object_data), headers=headers)
X = post_request(url=url, data=json.dumps(object_data))
print(time.time() - start_time)
print(X)