-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha.py
More file actions
53 lines (40 loc) · 1.49 KB
/
captcha.py
File metadata and controls
53 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
from dataclasses import dataclass
from typing import Awaitable, Callable, Literal, Optional
from .models import CaptchaDiagnostics
CaptchaPolicy = Literal["abort", "callback"]
CaptchaAction = Literal["abort", "retry_new_session", "wait_until_cleared"]
CaptchaSource = Literal["extension", "gateway", "runtime"]
@dataclass
class CaptchaContext:
run_id: str
step_index: int
url: str
source: CaptchaSource
captcha: CaptchaDiagnostics
screenshot_path: Optional[str] = None
frames_dir: Optional[str] = None
snapshot_path: Optional[str] = None
live_session_url: Optional[str] = None
meta: Optional[dict[str, str]] = None
@dataclass
class CaptchaResolution:
action: CaptchaAction
message: Optional[str] = None
handled_by: Optional[Literal["human", "customer_system", "unknown"]] = None
timeout_ms: Optional[int] = None
poll_ms: Optional[int] = None
CaptchaHandler = Callable[[CaptchaContext], CaptchaResolution | Awaitable[CaptchaResolution]]
@dataclass
class CaptchaOptions:
policy: CaptchaPolicy = "abort"
min_confidence: float = 0.7
timeout_ms: int = 120_000
poll_ms: int = 1_000
max_retries_new_session: int = 1
handler: Optional[CaptchaHandler] = None
reset_session: Optional[Callable[[], Awaitable[None]]] = None
class CaptchaHandlingError(RuntimeError):
def __init__(self, reason_code: str, message: str) -> None:
super().__init__(message)
self.reason_code = reason_code