宜搭api完善
This commit is contained in:
@@ -32,7 +32,7 @@ class YDAPI:
|
||||
token = res.json().get('accessToken')
|
||||
return token
|
||||
|
||||
def update_from(self, token, formInstanceId, data_new):
|
||||
def update_from(self, token, formInstanceId, data_new,delay=2, max_retries=10):
|
||||
"""
|
||||
函数功能:更新表单内容
|
||||
|
||||
@@ -62,10 +62,19 @@ class YDAPI:
|
||||
"updateFormDataJson": json.dumps(data_new, cls=NpEncoder),
|
||||
|
||||
}
|
||||
|
||||
res = requests.put(api, headers=headers, json=payload)
|
||||
|
||||
return res
|
||||
attempt = 0
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法更新表单数据,跳过本次请求。")
|
||||
break
|
||||
try:
|
||||
res = requests.get(api, headers=headers,timeout=10)
|
||||
res.raise_for_status() # 如果响应状态码不是2xx,则抛出HTTPError
|
||||
return res.json()
|
||||
except (requests.exceptions.RequestException, Exception) as e:
|
||||
print(f"请求出现异常: {e}, 正在重试({attempt + 1}/{max_retries})...")
|
||||
time.sleep(delay) # 等待指定的延迟时间后再次尝试
|
||||
attempt += 1
|
||||
|
||||
def processes_instancesInfos(self, token, id, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", delay=2, max_retries=10):
|
||||
@@ -106,7 +115,7 @@ class YDAPI:
|
||||
attempt += 1
|
||||
|
||||
def read_processes(self, token, formUuid, page, n, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2"):
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", max_retries=10,delay=2):
|
||||
"""
|
||||
函数功能:读取普通表单的所有数据
|
||||
|
||||
@@ -134,9 +143,21 @@ class YDAPI:
|
||||
'currentPage': page,
|
||||
'pageSize': n
|
||||
}
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
print(formData)
|
||||
return res.json()
|
||||
attempt = 0
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法获取普通表单数据,跳过本次请求。")
|
||||
break
|
||||
|
||||
try:
|
||||
res = requests.post(api, headers=headers, json=formData)
|
||||
res.raise_for_status() # 如果返回状态码不是2xx,抛出异常
|
||||
return res.json()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.warning(f"请求异常: {e},正在尝试第 {attempt + 1} 次重试...")
|
||||
time.sleep(delay)
|
||||
attempt += 1
|
||||
|
||||
def read_processes_instances(self, token, formUuid, page, n, appType="APP_UYZ0KG6L0CCNV80GZ66O",
|
||||
systemToken="XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2", instanceStatus="RUNNING",
|
||||
@@ -220,7 +241,7 @@ class YDAPI:
|
||||
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法获取流程实例数据,跳过本次请求。")
|
||||
error_task_logger.error(f"请求失败,已达最大重试次数 {max_retries},无法获取审批数据,跳过本次请求。")
|
||||
break
|
||||
|
||||
try:
|
||||
@@ -256,13 +277,6 @@ class YDAPI:
|
||||
"x-acs-dingtalk-access-token": token
|
||||
|
||||
}
|
||||
#
|
||||
# prams = {
|
||||
# "systemToken": systemToken,
|
||||
# "appType": appType,
|
||||
# "userId": userId,
|
||||
# "language": "zh_CN",
|
||||
# }
|
||||
|
||||
while True:
|
||||
if attempt >= max_retries:
|
||||
@@ -325,6 +339,7 @@ class YDAPI:
|
||||
"language": "zh_CN",
|
||||
"taskId": int(taskId)
|
||||
}
|
||||
|
||||
res = requests.post(api, headers=headers, json=payload)
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user