refactor: 移除reCAPTCHA任务的异常处理和超时逻辑以简化代码
This commit is contained in:
parent
7c645e93ca
commit
8470c1f21a
70
onoe.py
70
onoe.py
@ -262,43 +262,43 @@ def solve_recaptcha_v3_with_proxy(
|
|||||||
|
|
||||||
last_error = None
|
last_error = None
|
||||||
for attempt in range(1, max_task_retries + 1):
|
for attempt in range(1, max_task_retries + 1):
|
||||||
try:
|
# try:
|
||||||
encoded_query = quote(keyword, safe="")
|
encoded_query = quote(keyword, safe="")
|
||||||
payload = {
|
payload = {
|
||||||
"clientKey": "CAP-A76C932D4C6CCB3CA748F77FDC07D996",
|
"clientKey": "CAP-A76C932D4C6CCB3CA748F77FDC07D996",
|
||||||
"task": {
|
"task": {
|
||||||
"type": "ReCaptchaV3Task",
|
"type": "ReCaptchaV3Task",
|
||||||
"websiteURL": f"https://www.dailymotion.com/search/{encoded_query}/top-results",
|
"websiteURL": f"https://www.dailymotion.com/search/{encoded_query}/top-results",
|
||||||
"websiteKey": "6LeOJBIrAAAAAPMIjyYvo-eN_9W1HDOkrEqHR8tM",
|
"websiteKey": "6LeOJBIrAAAAAPMIjyYvo-eN_9W1HDOkrEqHR8tM",
|
||||||
"pageAction": "",
|
"pageAction": "",
|
||||||
"minScore": 0.5
|
"minScore": 0.5
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resp = requests.post(create_url, json=payload, headers=headers, timeout=30)
|
}
|
||||||
logger.info(f"[token] 发送 payload:{payload}")
|
resp = requests.post(create_url, json=payload, headers=headers, timeout=30)
|
||||||
resp.raise_for_status()
|
logger.info(f"[token] 发送 payload:{payload}")
|
||||||
task_id = resp.json()["taskId"]
|
resp.raise_for_status()
|
||||||
logger.info(f"task_id: {resp.text}")
|
task_id = resp.json()["taskId"]
|
||||||
# 轮询获取结果
|
logger.info(f"task_id: {resp.text}")
|
||||||
check_payload = {"clientKey": "CAP-A76C932D4C6CCB3CA748F77FDC07D996", "taskId": task_id}
|
# 轮询获取结果
|
||||||
for i in range(max_poll_attempts):
|
check_payload = {"clientKey": "CAP-A76C932D4C6CCB3CA748F77FDC07D996", "taskId": task_id}
|
||||||
r = requests.post(result_url, json=check_payload, headers=headers, timeout=10)
|
for i in range(max_poll_attempts):
|
||||||
r.raise_for_status()
|
r = requests.post(result_url, json=check_payload, headers=headers, timeout=10)
|
||||||
result = r.json()
|
r.raise_for_status()
|
||||||
logger.info(f"第{i}次,task_id:{task_id},结果:{result}")
|
result = r.json()
|
||||||
if result.get("status") == "ready":
|
logger.info(f"第{i}次,task_id:{task_id},结果:{result}")
|
||||||
return result["solution"]["token"]
|
if result.get("status") == "ready":
|
||||||
time.sleep(polling_interval)
|
return result["solution"]["token"]
|
||||||
|
time.sleep(polling_interval)
|
||||||
|
|
||||||
raise TimeoutError(f"任务 {task_id} 在轮询 {max_poll_attempts} 次后未完成")
|
# raise TimeoutError(f"任务 {task_id} 在轮询 {max_poll_attempts} 次后未完成")
|
||||||
|
#
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
last_error = e
|
# last_error = e
|
||||||
if attempt < max_task_retries:
|
# if attempt < max_task_retries:
|
||||||
time.sleep(2)
|
# time.sleep(2)
|
||||||
continue
|
# continue
|
||||||
else:
|
# else:
|
||||||
break
|
# break
|
||||||
|
|
||||||
raise Exception(f"创建或获取 reCAPTCHA v3 token 失败: {last_error}")
|
raise Exception(f"创建或获取 reCAPTCHA v3 token 失败: {last_error}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user