fix: ложный status ok и падение без captcha_type
- без captcha_type шаг антибота пропускается, на неизвестный тип — понятная ошибка - wait_for и pass_challenge при неудаче падают, а не возвращают текст ошибки как результат - status "err" ставится по упавшему действию (раньше проверялся несуществующий ключ error) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c54500b178
commit
df108dae3f
4 files changed
+13
-8
No files matched your search
@@ -31,6 +31,10 @@ async def pass_challenges(
|
||||
success_locator: str | None = None,
|
||||
detect_locator: str | None = None,
|
||||
timeout_ms=120_000) -> ChallengeOutcome:
|
||||
if not antibot_name:
|
||||
# провайдер не указан — антибот не проходим, сразу к действиям
|
||||
return ChallengeOutcome(True, reason="antibot not requested")
|
||||
|
||||
# установка дедлайна
|
||||
deadline = time.monotonic() + timeout_ms / 1000
|
||||
|
||||
|
||||
@@ -29,4 +29,5 @@ async def select_one(page: Page, provider_name: str, **kwargs) -> AntiBotProvide
|
||||
provider.configure(**kwargs)
|
||||
return provider
|
||||
else:
|
||||
raise ProviderNotDetected()
|
||||
known = ", ".join(p.provider for p in _detectors)
|
||||
raise ProviderNotDetected(f"unknown captcha_type {provider_name!r}, expected one of: {known}")
|
||||
+3
-4
@@ -74,10 +74,7 @@ async def inner_html(page: Page, act: ActionRequest, **kwargs) -> str | None:
|
||||
async def wait_for(page: Page, act: ActionRequest, **kwargs) -> str | None:
|
||||
assert act.selector
|
||||
assert 1 <= act.timeout <= 7200
|
||||
try:
|
||||
await page.wait_for_selector(act.selector, timeout=act.timeout * 1000)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
await page.wait_for_selector(act.selector, timeout=act.timeout * 1000)
|
||||
|
||||
|
||||
@register
|
||||
@@ -92,6 +89,8 @@ async def pass_challenge(
|
||||
success_locator=act.selector or success_locator,
|
||||
detect_locator=detect_locator
|
||||
)
|
||||
if not result.cleared:
|
||||
raise Exception(f"challenge not passed: {result.reason}")
|
||||
return result.reason
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -135,12 +135,13 @@ async def solve(
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
result_payload = {
|
||||
"error": str(e),
|
||||
"error": str(e) or type(e).__name__,
|
||||
"status": False
|
||||
}
|
||||
else:
|
||||
status = not "error" in result["actions"][-1]
|
||||
error = ["Something error", None][status]
|
||||
failed = [a for a in result["actions"] if a.get("ok") is False]
|
||||
status = not failed
|
||||
error = None if status else f"{failed[0]['type']}: {failed[0].get('result')}"
|
||||
|
||||
result_payload = {
|
||||
"status": ["err", "ok"][status],
|
||||
|
||||
Reference in new issue
Block a user