python-rucaptcha 6.6.0__py3-none-any.whl → 6.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_rucaptcha/__version__.py +1 -1
- python_rucaptcha/captchaai.py +160 -0
- python_rucaptcha/core/base.py +21 -0
- python_rucaptcha/core/captchaai.py +685 -0
- python_rucaptcha/core/data/__init__.py +1 -0
- python_rucaptcha/core/data/captchaai_legacy_profiles.json +19 -0
- python_rucaptcha/core/data/captchaai_profiles.json +26 -0
- python_rucaptcha/core/enums.py +2 -0
- python_rucaptcha/core/serializer.py +7 -3
- {python_rucaptcha-6.6.0.dist-info → python_rucaptcha-6.7.0.dist-info}/METADATA +58 -2
- {python_rucaptcha-6.6.0.dist-info → python_rucaptcha-6.7.0.dist-info}/RECORD +14 -9
- {python_rucaptcha-6.6.0.dist-info → python_rucaptcha-6.7.0.dist-info}/WHEEL +1 -1
- {python_rucaptcha-6.6.0.dist-info → python_rucaptcha-6.7.0.dist-info}/licenses/LICENSE +0 -0
- {python_rucaptcha-6.6.0.dist-info → python_rucaptcha-6.7.0.dist-info}/top_level.txt +0 -0
python_rucaptcha/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "6.
|
|
1
|
+
__version__ = "6.7.0"
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Native, future-compatible CaptchaAI classic API client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Mapping
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
from requests.adapters import HTTPAdapter
|
|
9
|
+
|
|
10
|
+
from .core import captchaai as transport
|
|
11
|
+
from .core.enums import ServiceEnm
|
|
12
|
+
from .core.config import RETRIES
|
|
13
|
+
from .core.serializer import CaptchaOptionsSer
|
|
14
|
+
|
|
15
|
+
CaptchaAIFile = transport.CaptchaAIFile
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CaptchaAI:
|
|
19
|
+
"""Client for CaptchaAI's classic multipart API.
|
|
20
|
+
|
|
21
|
+
A packaged profile can validate a documented method contract. Omitting the
|
|
22
|
+
profile allows provider-native parameters for methods not yet represented
|
|
23
|
+
in the package metadata.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
key: CaptchaAI API key used for requests.
|
|
27
|
+
method: Provider method submitted by the client.
|
|
28
|
+
params: Provider-native scalar parameters.
|
|
29
|
+
files: Multipart file parts keyed by provider field name.
|
|
30
|
+
profile: Optional packaged profile name.
|
|
31
|
+
poll: Whether to poll for a result after submission.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
rucaptcha_key: str,
|
|
37
|
+
method: str | None = None,
|
|
38
|
+
params: Mapping[str, Any] | None = None,
|
|
39
|
+
*,
|
|
40
|
+
files: Mapping[str, CaptchaAIFile] | None = None,
|
|
41
|
+
profile: str | None = None,
|
|
42
|
+
poll: bool | None = None,
|
|
43
|
+
sleep_time: int = 10,
|
|
44
|
+
):
|
|
45
|
+
"""Create a client for one CaptchaAI method.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
rucaptcha_key: API key used for CaptchaAI requests.
|
|
49
|
+
method: Provider-native method name. Required unless ``profile``
|
|
50
|
+
supplies the method.
|
|
51
|
+
params: Provider-native scalar parameters.
|
|
52
|
+
files: Multipart file parts keyed by provider field name.
|
|
53
|
+
profile: Optional packaged profile used for validation and defaults.
|
|
54
|
+
poll: Whether to poll after submission. If omitted, the profile
|
|
55
|
+
determines the default and native methods poll by default.
|
|
56
|
+
sleep_time: Seconds between result polls.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
ValueError: If neither ``method`` nor ``profile`` is supplied.
|
|
60
|
+
"""
|
|
61
|
+
if method is None:
|
|
62
|
+
if profile is None:
|
|
63
|
+
raise ValueError("CaptchaAI requires a method or a documented profile")
|
|
64
|
+
method = transport.profile_method(profile)
|
|
65
|
+
|
|
66
|
+
self.key = rucaptcha_key
|
|
67
|
+
self.method = method
|
|
68
|
+
self.params = dict(params or {})
|
|
69
|
+
self.files = dict(files or {})
|
|
70
|
+
self.profile = profile
|
|
71
|
+
self.poll = poll
|
|
72
|
+
self.options = CaptchaOptionsSer(sleep_time=sleep_time, service_type=ServiceEnm.CAPTCHAAI)
|
|
73
|
+
self.options.urls_set()
|
|
74
|
+
self.session = requests.Session()
|
|
75
|
+
self.session.mount("http://", HTTPAdapter(max_retries=RETRIES))
|
|
76
|
+
self.session.mount("https://", HTTPAdapter(max_retries=RETRIES))
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def profiles(cls) -> tuple[str, ...]:
|
|
80
|
+
"""List the packaged CaptchaAI profile names.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Profile names available for declarative validation.
|
|
84
|
+
"""
|
|
85
|
+
return transport.profiles()
|
|
86
|
+
|
|
87
|
+
def captcha_handler(self) -> dict[str, Any]:
|
|
88
|
+
"""Submit the configured method and optionally poll for its result.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
A normalized result mapping containing either the solution or an
|
|
92
|
+
error description.
|
|
93
|
+
"""
|
|
94
|
+
return transport.solve_native(
|
|
95
|
+
key=self.key,
|
|
96
|
+
method=self.method,
|
|
97
|
+
params=self.params,
|
|
98
|
+
files=self.files,
|
|
99
|
+
profile=self.profile,
|
|
100
|
+
poll=self.poll,
|
|
101
|
+
url_request=self.options.url_request,
|
|
102
|
+
url_response=self.options.url_response,
|
|
103
|
+
sleep_time=self.options.sleep_time,
|
|
104
|
+
session=self.session,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
async def aio_captcha_handler(self) -> dict[str, Any]:
|
|
108
|
+
"""Asynchronously submit the method and optionally poll for its result.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
A normalized result mapping containing either the solution or an
|
|
112
|
+
error description.
|
|
113
|
+
"""
|
|
114
|
+
return await transport.aio_solve_native(
|
|
115
|
+
key=self.key,
|
|
116
|
+
method=self.method,
|
|
117
|
+
params=self.params,
|
|
118
|
+
files=self.files,
|
|
119
|
+
profile=self.profile,
|
|
120
|
+
poll=self.poll,
|
|
121
|
+
url_request=self.options.url_request,
|
|
122
|
+
url_response=self.options.url_response,
|
|
123
|
+
sleep_time=self.options.sleep_time,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def get_balance(self) -> dict[str, Any]:
|
|
127
|
+
"""Fetch the account balance through the CaptchaAI control API.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
The provider response with the balance value when successful, or
|
|
131
|
+
the normalized error mapping returned by the transport.
|
|
132
|
+
"""
|
|
133
|
+
return transport.control(self.key, "balance", self.options.url_response, session=self.session)
|
|
134
|
+
|
|
135
|
+
async def aio_get_balance(self) -> dict[str, Any]:
|
|
136
|
+
"""Asynchronously fetch the account balance.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
The provider response with the balance value when successful, or
|
|
140
|
+
the normalized error mapping returned by the transport.
|
|
141
|
+
"""
|
|
142
|
+
return await transport.aio_control(self.key, "balance", self.options.url_response)
|
|
143
|
+
|
|
144
|
+
def get_threads_info(self) -> dict[str, Any]:
|
|
145
|
+
"""Fetch total and active thread information.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
The provider response with thread information, or the normalized
|
|
149
|
+
error mapping returned by the transport.
|
|
150
|
+
"""
|
|
151
|
+
return transport.control(self.key, "threads_info", self.options.url_response, session=self.session)
|
|
152
|
+
|
|
153
|
+
async def aio_get_threads_info(self) -> dict[str, Any]:
|
|
154
|
+
"""Asynchronously fetch total and active thread information.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
The provider response with thread information, or the normalized
|
|
158
|
+
error mapping returned by the transport.
|
|
159
|
+
"""
|
|
160
|
+
return await transport.aio_control(self.key, "threads_info", self.options.url_response)
|
python_rucaptcha/core/base.py
CHANGED
|
@@ -82,6 +82,17 @@ class BaseCaptcha:
|
|
|
82
82
|
Method processing captcha solving task creation result
|
|
83
83
|
:param kwargs: additional params for Requests library
|
|
84
84
|
"""
|
|
85
|
+
# CaptchaAI speaks the classic in.php/res.php API, not the JSON createTask API.
|
|
86
|
+
if self.params.service_type == ServiceEnm.CAPTCHAAI.value:
|
|
87
|
+
from . import captchaai
|
|
88
|
+
|
|
89
|
+
return captchaai.solve(
|
|
90
|
+
create_task_payload=self.create_task_payload,
|
|
91
|
+
url_request=self.params.url_request,
|
|
92
|
+
url_response=self.params.url_response,
|
|
93
|
+
sleep_time=self.params.sleep_time,
|
|
94
|
+
session=self.session,
|
|
95
|
+
)
|
|
85
96
|
try:
|
|
86
97
|
response = GetTaskResultResponseSer(
|
|
87
98
|
**self.session.post(self.params.url_request, json=self.create_task_payload, **kwargs).json()
|
|
@@ -126,6 +137,16 @@ class BaseCaptcha:
|
|
|
126
137
|
"""
|
|
127
138
|
Method processing async captcha solving task creation result
|
|
128
139
|
"""
|
|
140
|
+
# CaptchaAI speaks the classic in.php/res.php API, not the JSON createTask API.
|
|
141
|
+
if self.params.service_type == ServiceEnm.CAPTCHAAI.value:
|
|
142
|
+
from . import captchaai
|
|
143
|
+
|
|
144
|
+
return await captchaai.aio_solve(
|
|
145
|
+
create_task_payload=self.create_task_payload,
|
|
146
|
+
url_request=self.params.url_request,
|
|
147
|
+
url_response=self.params.url_response,
|
|
148
|
+
sleep_time=self.params.sleep_time,
|
|
149
|
+
)
|
|
129
150
|
try:
|
|
130
151
|
# make async or sync request
|
|
131
152
|
response = await self.__aio_create_task()
|
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
"""Transport CaptchaAI classic multipart requests using packaged metadata.
|
|
2
|
+
|
|
3
|
+
Provider contracts are data-driven, so native callers can submit documented
|
|
4
|
+
methods and future methods without adding task-type branches here.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import time
|
|
11
|
+
import asyncio
|
|
12
|
+
import logging
|
|
13
|
+
from typing import Any, Mapping
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from functools import lru_cache
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
|
|
18
|
+
import aiohttp
|
|
19
|
+
import requests
|
|
20
|
+
|
|
21
|
+
from .config import attempts_generator
|
|
22
|
+
from .serializer import GetTaskResultResponseSer
|
|
23
|
+
|
|
24
|
+
REQUEST_TIMEOUT = 30
|
|
25
|
+
_PENDING = "CAPCHA_NOT_READY"
|
|
26
|
+
_RESERVED_FIELDS = {"key", "method", "json"}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class CaptchaAIFile:
|
|
31
|
+
"""Describe one binary part in a native CaptchaAI multipart request.
|
|
32
|
+
|
|
33
|
+
Attributes:
|
|
34
|
+
content: Bytes sent as the multipart field body.
|
|
35
|
+
filename: Filename presented to the provider.
|
|
36
|
+
content_type: MIME type presented for the file part.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
content: bytes
|
|
40
|
+
filename: str = "captcha.bin"
|
|
41
|
+
content_type: str = "application/octet-stream"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@lru_cache(maxsize=1)
|
|
45
|
+
def _metadata() -> dict[str, Any]:
|
|
46
|
+
"""Load the packaged native CaptchaAI profile metadata once.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
Parsed profile and control-operation metadata.
|
|
50
|
+
"""
|
|
51
|
+
data_path = Path(__file__).with_name("data") / "captchaai_profiles.json"
|
|
52
|
+
return json.loads(data_path.read_text(encoding="utf-8"))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@lru_cache(maxsize=1)
|
|
56
|
+
def _legacy_metadata() -> dict[str, Any]:
|
|
57
|
+
"""Load the packaged legacy task translation metadata once.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Parsed mappings from library task names to CaptchaAI profiles.
|
|
61
|
+
"""
|
|
62
|
+
data_path = Path(__file__).with_name("data") / "captchaai_legacy_profiles.json"
|
|
63
|
+
return json.loads(data_path.read_text(encoding="utf-8"))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def profiles() -> tuple[str, ...]:
|
|
67
|
+
"""Return the packaged CaptchaAI profile names.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Profile names available for declarative validation.
|
|
71
|
+
"""
|
|
72
|
+
return tuple(_metadata()["profiles"])
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def profile_method(profile_name: str) -> str:
|
|
76
|
+
"""Return the native method configured by a packaged profile.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
profile_name: Name of the packaged profile to inspect.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Provider-native method name for the profile.
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
ValueError: If ``profile_name`` is not packaged.
|
|
86
|
+
"""
|
|
87
|
+
return str(_profile(profile_name)["method"])
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _err(request: Any) -> dict[str, Any]:
|
|
91
|
+
"""Normalize a transport or provider failure into a result mapping.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
request: Error value or provider error text to expose in the result.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
A failed ``GetTaskResultResponseSer`` mapping.
|
|
98
|
+
"""
|
|
99
|
+
message = str(request) if request is not None else "ERROR_UNKNOWN"
|
|
100
|
+
return GetTaskResultResponseSer(
|
|
101
|
+
status="failed",
|
|
102
|
+
errorId=12,
|
|
103
|
+
errorCode=message,
|
|
104
|
+
errorDescription=f"CaptchaAI returned: {message}",
|
|
105
|
+
).to_dict()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _profile(profile_name: str | None) -> dict[str, Any]:
|
|
109
|
+
"""Resolve an optional packaged profile.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
profile_name: Profile name, or ``None`` for unprofiled native calls.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Profile metadata, or an empty mapping when no profile is selected.
|
|
116
|
+
|
|
117
|
+
Raises:
|
|
118
|
+
ValueError: If the requested profile is not packaged.
|
|
119
|
+
"""
|
|
120
|
+
if profile_name is None:
|
|
121
|
+
return {}
|
|
122
|
+
try:
|
|
123
|
+
return _metadata()["profiles"][profile_name]
|
|
124
|
+
except KeyError as error:
|
|
125
|
+
raise ValueError(f"Unknown CaptchaAI profile {profile_name!r}") from error
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _prepare_params(
|
|
129
|
+
method: str,
|
|
130
|
+
params: Mapping[str, Any] | None,
|
|
131
|
+
files: Mapping[str, CaptchaAIFile] | None,
|
|
132
|
+
profile_name: str | None,
|
|
133
|
+
) -> tuple[str, dict[str, Any], dict[str, CaptchaAIFile], dict[str, Any]]:
|
|
134
|
+
"""Apply profile defaults and validate a native method request.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
method: Provider-native method name.
|
|
138
|
+
params: Scalar provider parameters.
|
|
139
|
+
files: Binary multipart fields.
|
|
140
|
+
profile_name: Optional packaged profile used for validation.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
The method, prepared scalar parameters, file parts, and profile data.
|
|
144
|
+
|
|
145
|
+
Raises:
|
|
146
|
+
ValueError: If the request violates reserved-field, profile, or file
|
|
147
|
+
validation rules.
|
|
148
|
+
"""
|
|
149
|
+
if not method:
|
|
150
|
+
raise ValueError("CaptchaAI method is required")
|
|
151
|
+
profile = _profile(profile_name)
|
|
152
|
+
supplied = dict(params or {})
|
|
153
|
+
if invalid := _RESERVED_FIELDS.intersection(supplied):
|
|
154
|
+
raise ValueError(f"CaptchaAI params cannot override reserved fields: {sorted(invalid)}")
|
|
155
|
+
|
|
156
|
+
prepared_files = dict(files or {})
|
|
157
|
+
for field, value in prepared_files.items():
|
|
158
|
+
if not isinstance(value, CaptchaAIFile):
|
|
159
|
+
raise ValueError(f"CaptchaAI file field {field!r} must be a CaptchaAIFile")
|
|
160
|
+
|
|
161
|
+
prepared = {**profile.get("defaults", {}), **supplied}
|
|
162
|
+
expected_method = profile.get("method")
|
|
163
|
+
if expected_method is not None and method != expected_method:
|
|
164
|
+
raise ValueError(f"Profile {profile_name!r} requires method {expected_method!r}")
|
|
165
|
+
|
|
166
|
+
file_fields = set(profile.get("file_fields", []))
|
|
167
|
+
missing = [
|
|
168
|
+
field
|
|
169
|
+
for field in profile.get("required", [])
|
|
170
|
+
if (field not in prepared_files if field in file_fields else field not in prepared)
|
|
171
|
+
]
|
|
172
|
+
if missing:
|
|
173
|
+
raise ValueError(
|
|
174
|
+
f"CaptchaAI profile {profile_name!r} is missing required fields: {', '.join(missing)}"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
unexpected_files = set(prepared_files).difference(file_fields) if file_fields else set()
|
|
178
|
+
if unexpected_files and profile_name is not None:
|
|
179
|
+
raise ValueError(
|
|
180
|
+
f"CaptchaAI profile {profile_name!r} does not accept files: {sorted(unexpected_files)}"
|
|
181
|
+
)
|
|
182
|
+
return method, prepared, prepared_files, profile
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _proxy_params(task: Mapping[str, Any]) -> dict[str, str]:
|
|
186
|
+
"""Translate canonical proxy fields to CaptchaAI classic API fields.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
task: Legacy library task containing canonical proxy fields.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
Provider-native ``proxy`` and ``proxytype`` fields, or an empty mapping
|
|
193
|
+
when no proxy fields are present.
|
|
194
|
+
|
|
195
|
+
Raises:
|
|
196
|
+
ValueError: If required proxy fields are incomplete or invalid.
|
|
197
|
+
"""
|
|
198
|
+
fields = ("proxyType", "proxyAddress", "proxyPort", "proxyLogin", "proxyPassword")
|
|
199
|
+
if not any(task.get(field) is not None for field in fields):
|
|
200
|
+
return {}
|
|
201
|
+
|
|
202
|
+
proxy_type = task.get("proxyType")
|
|
203
|
+
proxy_address = task.get("proxyAddress")
|
|
204
|
+
proxy_port = task.get("proxyPort")
|
|
205
|
+
if not all((proxy_type, proxy_address, proxy_port)):
|
|
206
|
+
raise ValueError("proxyType, proxyAddress, and proxyPort must be supplied together")
|
|
207
|
+
|
|
208
|
+
normalized_type = str(proxy_type).upper()
|
|
209
|
+
if normalized_type not in {"HTTP", "HTTPS", "SOCKS4", "SOCKS5"}:
|
|
210
|
+
raise ValueError("proxyType must be HTTP, HTTPS, SOCKS4, or SOCKS5")
|
|
211
|
+
|
|
212
|
+
proxy_login = task.get("proxyLogin")
|
|
213
|
+
proxy_password = task.get("proxyPassword")
|
|
214
|
+
if (proxy_login is None) != (proxy_password is None):
|
|
215
|
+
raise ValueError("proxyLogin and proxyPassword must be supplied together")
|
|
216
|
+
|
|
217
|
+
proxy = f"{proxy_address}:{proxy_port}"
|
|
218
|
+
if proxy_login is not None:
|
|
219
|
+
proxy = f"{proxy_login}:{proxy_password}@{proxy}"
|
|
220
|
+
return {"proxy": proxy, "proxytype": normalized_type}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _legacy_request(task: Mapping[str, Any]) -> tuple[str, dict[str, Any], str | None]:
|
|
224
|
+
"""Translate a legacy task through packaged compatibility metadata.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
task: Existing library task payload.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
Provider method, provider-native parameters, and optional profile name.
|
|
231
|
+
|
|
232
|
+
Raises:
|
|
233
|
+
ValueError: If no compatibility profile exists or explicit parameters
|
|
234
|
+
are not a mapping.
|
|
235
|
+
"""
|
|
236
|
+
explicit_method = task.get("captchaai_method")
|
|
237
|
+
explicit_profile = task.get("captchaai_profile")
|
|
238
|
+
if explicit_method is not None:
|
|
239
|
+
explicit_params = task.get("captchaai_params", {})
|
|
240
|
+
if not isinstance(explicit_params, Mapping):
|
|
241
|
+
raise ValueError("captchaai_params must be a mapping")
|
|
242
|
+
return str(explicit_method), dict(explicit_params), explicit_profile
|
|
243
|
+
|
|
244
|
+
task_type = getattr(task.get("type"), "value", task.get("type"))
|
|
245
|
+
task_config = _legacy_metadata().get(str(task_type))
|
|
246
|
+
if task_config is None:
|
|
247
|
+
raise ValueError(
|
|
248
|
+
"No CaptchaAI compatibility profile exists for this library task. "
|
|
249
|
+
"Use the native CaptchaAI client with method and params."
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
params: dict[str, Any] = {}
|
|
253
|
+
bool_int = set(task_config.get("bool_int", []))
|
|
254
|
+
for source, target in task_config.get("fields", {}).items():
|
|
255
|
+
if task.get(source) is not None:
|
|
256
|
+
value = task[source]
|
|
257
|
+
params[target] = int(bool(value)) if source in bool_int else value
|
|
258
|
+
if task_config.get("proxy"):
|
|
259
|
+
params.update(_proxy_params(task))
|
|
260
|
+
|
|
261
|
+
profile_name = task_config["profile"]
|
|
262
|
+
method = _profile(profile_name)["method"]
|
|
263
|
+
return method, params, profile_name
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _requests_form(
|
|
267
|
+
fields: Mapping[str, Any], files: Mapping[str, CaptchaAIFile]
|
|
268
|
+
) -> dict[str, tuple[Any, ...]]:
|
|
269
|
+
"""Build requests-compatible multipart parts.
|
|
270
|
+
|
|
271
|
+
Args:
|
|
272
|
+
fields: Scalar fields to encode as text parts.
|
|
273
|
+
files: Binary fields to encode with filename and MIME metadata.
|
|
274
|
+
|
|
275
|
+
Returns:
|
|
276
|
+
Multipart parts accepted by ``requests.Session.post``.
|
|
277
|
+
"""
|
|
278
|
+
form: dict[str, tuple[Any, ...]] = {name: (None, str(value)) for name, value in fields.items()}
|
|
279
|
+
for name, value in files.items():
|
|
280
|
+
form[name] = (value.filename, value.content, value.content_type)
|
|
281
|
+
return form
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _aio_form(fields: Mapping[str, Any], files: Mapping[str, CaptchaAIFile]) -> aiohttp.FormData:
|
|
285
|
+
"""Build an aiohttp multipart form from scalar and binary fields.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
fields: Scalar fields to encode as text parts.
|
|
289
|
+
files: Binary fields to encode with filename and MIME metadata.
|
|
290
|
+
|
|
291
|
+
Returns:
|
|
292
|
+
Multipart form suitable for an aiohttp POST request.
|
|
293
|
+
"""
|
|
294
|
+
form = aiohttp.FormData()
|
|
295
|
+
for name, value in fields.items():
|
|
296
|
+
form.add_field(name, str(value), content_type="text/plain")
|
|
297
|
+
for name, value in files.items():
|
|
298
|
+
form.add_field(name, value.content, filename=value.filename, content_type=value.content_type)
|
|
299
|
+
return form
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _response_payload(response: Any) -> dict[str, Any]:
|
|
303
|
+
"""Validate the JSON response shape expected by the transport.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
response: Decoded provider response.
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
The response as a dictionary.
|
|
310
|
+
|
|
311
|
+
Raises:
|
|
312
|
+
ValueError: If the response is not a JSON object.
|
|
313
|
+
"""
|
|
314
|
+
if not isinstance(response, dict):
|
|
315
|
+
raise ValueError("response is not a JSON object")
|
|
316
|
+
return response
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def _error_value(response: Mapping[str, Any]) -> Any:
|
|
320
|
+
"""Select the most useful provider error value from a response.
|
|
321
|
+
|
|
322
|
+
Args:
|
|
323
|
+
response: Provider response mapping.
|
|
324
|
+
|
|
325
|
+
Returns:
|
|
326
|
+
The first available provider error value, or ``ERROR_UNKNOWN``.
|
|
327
|
+
"""
|
|
328
|
+
return (
|
|
329
|
+
response.get("request")
|
|
330
|
+
or response.get("error")
|
|
331
|
+
or response.get("errorDescription")
|
|
332
|
+
or "ERROR_UNKNOWN"
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _ready(task_id: str | None, response: Mapping[str, Any], profile: Mapping[str, Any]) -> dict[str, Any]:
|
|
337
|
+
"""Normalize a successful provider response and apply profile aliases.
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
task_id: Provider task identifier, if the request was polled.
|
|
341
|
+
response: Successful provider response mapping.
|
|
342
|
+
profile: Profile metadata containing optional result aliases.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
A ready ``GetTaskResultResponseSer`` mapping.
|
|
346
|
+
"""
|
|
347
|
+
solution = {key: value for key, value in response.items() if key != "status"}
|
|
348
|
+
for alias, source in profile.get("aliases", {}).items():
|
|
349
|
+
if source in solution:
|
|
350
|
+
value = solution[source]
|
|
351
|
+
if alias == "click" and isinstance(value, str):
|
|
352
|
+
try:
|
|
353
|
+
value = json.loads(value)
|
|
354
|
+
except ValueError:
|
|
355
|
+
pass
|
|
356
|
+
solution[alias] = value
|
|
357
|
+
return GetTaskResultResponseSer(status="ready", solution=solution, taskId=task_id).to_dict()
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _is_success(response: Mapping[str, Any], profile: Mapping[str, Any]) -> bool:
|
|
361
|
+
"""Determine whether a response satisfies its profile success contract.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
response: Provider response mapping.
|
|
365
|
+
profile: Profile metadata containing optional success fields.
|
|
366
|
+
|
|
367
|
+
Returns:
|
|
368
|
+
``True`` when the standard status or all profile success fields match.
|
|
369
|
+
"""
|
|
370
|
+
if response.get("status") == 1:
|
|
371
|
+
return True
|
|
372
|
+
success_fields = profile.get("success_fields", [])
|
|
373
|
+
return bool(success_fields) and all(field in response for field in success_fields)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def _submit_url(url_request: str, profile: Mapping[str, Any]) -> str:
|
|
377
|
+
"""Resolve a profile-specific submission URL from the configured base URL.
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
url_request: Configured default submission URL.
|
|
381
|
+
profile: Profile metadata containing an optional submission path.
|
|
382
|
+
|
|
383
|
+
Returns:
|
|
384
|
+
Submission URL selected for the profile.
|
|
385
|
+
"""
|
|
386
|
+
path = profile.get("submit_path", "/in.php")
|
|
387
|
+
if path == "/in.php":
|
|
388
|
+
return url_request
|
|
389
|
+
return f"{url_request.rsplit('/', 1)[0]}{path}"
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def solve_native(
|
|
393
|
+
key: str,
|
|
394
|
+
method: str,
|
|
395
|
+
params: Mapping[str, Any] | None,
|
|
396
|
+
url_request: str,
|
|
397
|
+
url_response: str,
|
|
398
|
+
sleep_time: int,
|
|
399
|
+
*,
|
|
400
|
+
files: Mapping[str, CaptchaAIFile] | None = None,
|
|
401
|
+
profile: str | None = None,
|
|
402
|
+
poll: bool | None = None,
|
|
403
|
+
session: requests.Session | None = None,
|
|
404
|
+
) -> dict[str, Any]:
|
|
405
|
+
"""Submit and optionally poll any CaptchaAI classic API method.
|
|
406
|
+
|
|
407
|
+
Args:
|
|
408
|
+
key: CaptchaAI API key.
|
|
409
|
+
method: Provider-native method name.
|
|
410
|
+
params: Scalar provider parameters.
|
|
411
|
+
url_request: Submission URL.
|
|
412
|
+
url_response: Polling URL.
|
|
413
|
+
sleep_time: Seconds between polling attempts.
|
|
414
|
+
files: Optional binary multipart fields.
|
|
415
|
+
profile: Optional packaged profile name.
|
|
416
|
+
poll: Whether to poll after submission.
|
|
417
|
+
session: Optional requests session to reuse.
|
|
418
|
+
|
|
419
|
+
Returns:
|
|
420
|
+
A normalized ready or failed result mapping.
|
|
421
|
+
"""
|
|
422
|
+
try:
|
|
423
|
+
method, params, files, profile_data = _prepare_params(method, params, files, profile)
|
|
424
|
+
except ValueError as error:
|
|
425
|
+
return _err(error)
|
|
426
|
+
|
|
427
|
+
should_poll = profile_data.get("poll", True) if poll is None else poll
|
|
428
|
+
data = {"key": key, "method": method, "json": 1, **params}
|
|
429
|
+
http = session or requests.Session()
|
|
430
|
+
try:
|
|
431
|
+
response = http.post(
|
|
432
|
+
_submit_url(url_request, profile_data),
|
|
433
|
+
files=_requests_form(data, files),
|
|
434
|
+
timeout=REQUEST_TIMEOUT,
|
|
435
|
+
)
|
|
436
|
+
response.raise_for_status()
|
|
437
|
+
created = _response_payload(response.json())
|
|
438
|
+
except (requests.RequestException, ValueError) as error:
|
|
439
|
+
return _err(f"ERROR_SUBMIT {error}")
|
|
440
|
+
|
|
441
|
+
if not should_poll:
|
|
442
|
+
if _is_success(created, profile_data):
|
|
443
|
+
return _ready(None, created, profile_data)
|
|
444
|
+
return _err(_error_value(created))
|
|
445
|
+
if created.get("status") != 1 or not isinstance(created.get("request"), str):
|
|
446
|
+
return _err(_error_value(created))
|
|
447
|
+
|
|
448
|
+
task_id = created["request"]
|
|
449
|
+
time.sleep(sleep_time)
|
|
450
|
+
for _ in attempts_generator():
|
|
451
|
+
try:
|
|
452
|
+
response = http.post(
|
|
453
|
+
url_response,
|
|
454
|
+
files=_requests_form({"key": key, "action": "get", "id": task_id, "json": 1}, {}),
|
|
455
|
+
timeout=REQUEST_TIMEOUT,
|
|
456
|
+
)
|
|
457
|
+
response.raise_for_status()
|
|
458
|
+
result = _response_payload(response.json())
|
|
459
|
+
except (requests.RequestException, ValueError) as error:
|
|
460
|
+
return _err(f"ERROR_POLL {error}")
|
|
461
|
+
logging.info("CaptchaAI sync result received for task %s", task_id)
|
|
462
|
+
if result.get("request") == _PENDING:
|
|
463
|
+
time.sleep(sleep_time)
|
|
464
|
+
continue
|
|
465
|
+
if _is_success(result, profile_data):
|
|
466
|
+
return _ready(task_id, result, profile_data)
|
|
467
|
+
return _err(_error_value(result))
|
|
468
|
+
return _err("ERROR_TIMEOUT")
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
async def aio_solve_native(
|
|
472
|
+
key: str,
|
|
473
|
+
method: str,
|
|
474
|
+
params: Mapping[str, Any] | None,
|
|
475
|
+
url_request: str,
|
|
476
|
+
url_response: str,
|
|
477
|
+
sleep_time: int,
|
|
478
|
+
*,
|
|
479
|
+
files: Mapping[str, CaptchaAIFile] | None = None,
|
|
480
|
+
profile: str | None = None,
|
|
481
|
+
poll: bool | None = None,
|
|
482
|
+
) -> dict[str, Any]:
|
|
483
|
+
"""Asynchronously submit and optionally poll a CaptchaAI method.
|
|
484
|
+
|
|
485
|
+
Args:
|
|
486
|
+
key: CaptchaAI API key.
|
|
487
|
+
method: Provider-native method name.
|
|
488
|
+
params: Scalar provider parameters.
|
|
489
|
+
url_request: Submission URL.
|
|
490
|
+
url_response: Polling URL.
|
|
491
|
+
sleep_time: Seconds between polling attempts.
|
|
492
|
+
files: Optional binary multipart fields.
|
|
493
|
+
profile: Optional packaged profile name.
|
|
494
|
+
poll: Whether to poll after submission.
|
|
495
|
+
|
|
496
|
+
Returns:
|
|
497
|
+
A normalized ready or failed result mapping.
|
|
498
|
+
"""
|
|
499
|
+
try:
|
|
500
|
+
method, params, files, profile_data = _prepare_params(method, params, files, profile)
|
|
501
|
+
except ValueError as error:
|
|
502
|
+
return _err(error)
|
|
503
|
+
|
|
504
|
+
should_poll = profile_data.get("poll", True) if poll is None else poll
|
|
505
|
+
data = {"key": key, "method": method, "json": 1, **params}
|
|
506
|
+
timeout = aiohttp.ClientTimeout(total=REQUEST_TIMEOUT)
|
|
507
|
+
async with aiohttp.ClientSession(timeout=timeout) as http:
|
|
508
|
+
try:
|
|
509
|
+
async with http.post(
|
|
510
|
+
_submit_url(url_request, profile_data), data=_aio_form(data, files)
|
|
511
|
+
) as response:
|
|
512
|
+
response.raise_for_status()
|
|
513
|
+
created = _response_payload(await response.json(content_type=None))
|
|
514
|
+
except (aiohttp.ClientError, ValueError) as error:
|
|
515
|
+
return _err(f"ERROR_SUBMIT {error}")
|
|
516
|
+
|
|
517
|
+
if not should_poll:
|
|
518
|
+
if _is_success(created, profile_data):
|
|
519
|
+
return _ready(None, created, profile_data)
|
|
520
|
+
return _err(_error_value(created))
|
|
521
|
+
if created.get("status") != 1 or not isinstance(created.get("request"), str):
|
|
522
|
+
return _err(_error_value(created))
|
|
523
|
+
|
|
524
|
+
task_id = created["request"]
|
|
525
|
+
await asyncio.sleep(sleep_time)
|
|
526
|
+
for _ in attempts_generator():
|
|
527
|
+
try:
|
|
528
|
+
poll_data = {"key": key, "action": "get", "id": task_id, "json": 1}
|
|
529
|
+
async with http.post(url_response, data=_aio_form(poll_data, {})) as response:
|
|
530
|
+
response.raise_for_status()
|
|
531
|
+
result = _response_payload(await response.json(content_type=None))
|
|
532
|
+
except (aiohttp.ClientError, ValueError) as error:
|
|
533
|
+
return _err(f"ERROR_POLL {error}")
|
|
534
|
+
logging.info("CaptchaAI async result received for task %s", task_id)
|
|
535
|
+
if result.get("request") == _PENDING:
|
|
536
|
+
await asyncio.sleep(sleep_time)
|
|
537
|
+
continue
|
|
538
|
+
if _is_success(result, profile_data):
|
|
539
|
+
return _ready(task_id, result, profile_data)
|
|
540
|
+
return _err(_error_value(result))
|
|
541
|
+
return _err("ERROR_TIMEOUT")
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def solve(
|
|
545
|
+
create_task_payload: Mapping[str, Any],
|
|
546
|
+
url_request: str,
|
|
547
|
+
url_response: str,
|
|
548
|
+
sleep_time: int,
|
|
549
|
+
session: requests.Session | None = None,
|
|
550
|
+
) -> dict[str, Any]:
|
|
551
|
+
"""Solve a legacy library task through CaptchaAI compatibility metadata.
|
|
552
|
+
|
|
553
|
+
Args:
|
|
554
|
+
create_task_payload: Existing library create-task payload.
|
|
555
|
+
url_request: CaptchaAI submission URL.
|
|
556
|
+
url_response: CaptchaAI polling URL.
|
|
557
|
+
sleep_time: Seconds between polling attempts.
|
|
558
|
+
session: Optional requests session to reuse.
|
|
559
|
+
|
|
560
|
+
Returns:
|
|
561
|
+
A normalized ready or failed result mapping.
|
|
562
|
+
"""
|
|
563
|
+
try:
|
|
564
|
+
method, params, profile = _legacy_request(create_task_payload["task"])
|
|
565
|
+
except (KeyError, ValueError) as error:
|
|
566
|
+
return _err(error)
|
|
567
|
+
return solve_native(
|
|
568
|
+
key=str(create_task_payload["clientKey"]),
|
|
569
|
+
method=method,
|
|
570
|
+
params=params,
|
|
571
|
+
profile=profile,
|
|
572
|
+
url_request=url_request,
|
|
573
|
+
url_response=url_response,
|
|
574
|
+
sleep_time=sleep_time,
|
|
575
|
+
session=session,
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
async def aio_solve(
|
|
580
|
+
create_task_payload: Mapping[str, Any],
|
|
581
|
+
url_request: str,
|
|
582
|
+
url_response: str,
|
|
583
|
+
sleep_time: int,
|
|
584
|
+
) -> dict[str, Any]:
|
|
585
|
+
"""Asynchronously solve a legacy task through compatibility metadata.
|
|
586
|
+
|
|
587
|
+
Args:
|
|
588
|
+
create_task_payload: Existing library create-task payload.
|
|
589
|
+
url_request: CaptchaAI submission URL.
|
|
590
|
+
url_response: CaptchaAI polling URL.
|
|
591
|
+
sleep_time: Seconds between polling attempts.
|
|
592
|
+
|
|
593
|
+
Returns:
|
|
594
|
+
A normalized ready or failed result mapping.
|
|
595
|
+
"""
|
|
596
|
+
try:
|
|
597
|
+
method, params, profile = _legacy_request(create_task_payload["task"])
|
|
598
|
+
except (KeyError, ValueError) as error:
|
|
599
|
+
return _err(error)
|
|
600
|
+
return await aio_solve_native(
|
|
601
|
+
key=str(create_task_payload["clientKey"]),
|
|
602
|
+
method=method,
|
|
603
|
+
params=params,
|
|
604
|
+
profile=profile,
|
|
605
|
+
url_request=url_request,
|
|
606
|
+
url_response=url_response,
|
|
607
|
+
sleep_time=sleep_time,
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def control(
|
|
612
|
+
key: str,
|
|
613
|
+
name: str,
|
|
614
|
+
url_response: str,
|
|
615
|
+
session: requests.Session | None = None,
|
|
616
|
+
) -> dict[str, Any]:
|
|
617
|
+
"""Execute a declarative CaptchaAI control operation.
|
|
618
|
+
|
|
619
|
+
Args:
|
|
620
|
+
key: CaptchaAI API key.
|
|
621
|
+
name: Packaged control-operation name.
|
|
622
|
+
url_response: CaptchaAI control endpoint.
|
|
623
|
+
session: Optional requests session to reuse.
|
|
624
|
+
|
|
625
|
+
Returns:
|
|
626
|
+
The provider control response or a normalized failed result.
|
|
627
|
+
"""
|
|
628
|
+
try:
|
|
629
|
+
control_data = _metadata()["controls"][name]
|
|
630
|
+
except KeyError:
|
|
631
|
+
return _err(f"Unknown CaptchaAI control operation {name!r}")
|
|
632
|
+
|
|
633
|
+
try:
|
|
634
|
+
response = (session or requests.Session()).post(
|
|
635
|
+
url_response,
|
|
636
|
+
files=_requests_form({"key": key, "json": 1, "action": control_data["action"]}, {}),
|
|
637
|
+
timeout=REQUEST_TIMEOUT,
|
|
638
|
+
)
|
|
639
|
+
response.raise_for_status()
|
|
640
|
+
payload = _response_payload(response.json())
|
|
641
|
+
except (requests.RequestException, ValueError) as error:
|
|
642
|
+
return _err(f"ERROR_CONTROL {error}")
|
|
643
|
+
|
|
644
|
+
if payload.get("status") == 0:
|
|
645
|
+
return _err(_error_value(payload))
|
|
646
|
+
result = {field: value for field, value in payload.items() if field != "status"}
|
|
647
|
+
for alias, source in control_data.get("aliases", {}).items():
|
|
648
|
+
if source in result:
|
|
649
|
+
result[alias] = result[source]
|
|
650
|
+
return result
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
async def aio_control(key: str, name: str, url_response: str) -> dict[str, Any]:
|
|
654
|
+
"""Asynchronously execute a declarative CaptchaAI control operation.
|
|
655
|
+
|
|
656
|
+
Args:
|
|
657
|
+
key: CaptchaAI API key.
|
|
658
|
+
name: Packaged control-operation name.
|
|
659
|
+
url_response: CaptchaAI control endpoint.
|
|
660
|
+
|
|
661
|
+
Returns:
|
|
662
|
+
The provider control response or a normalized failed result.
|
|
663
|
+
"""
|
|
664
|
+
try:
|
|
665
|
+
control_data = _metadata()["controls"][name]
|
|
666
|
+
except KeyError:
|
|
667
|
+
return _err(f"Unknown CaptchaAI control operation {name!r}")
|
|
668
|
+
|
|
669
|
+
timeout = aiohttp.ClientTimeout(total=REQUEST_TIMEOUT)
|
|
670
|
+
try:
|
|
671
|
+
async with aiohttp.ClientSession(timeout=timeout) as http:
|
|
672
|
+
data = {"key": key, "json": 1, "action": control_data["action"]}
|
|
673
|
+
async with http.post(url_response, data=_aio_form(data, {})) as response:
|
|
674
|
+
response.raise_for_status()
|
|
675
|
+
payload = _response_payload(await response.json(content_type=None))
|
|
676
|
+
except (aiohttp.ClientError, ValueError) as error:
|
|
677
|
+
return _err(f"ERROR_CONTROL {error}")
|
|
678
|
+
|
|
679
|
+
if payload.get("status") == 0:
|
|
680
|
+
return _err(_error_value(payload))
|
|
681
|
+
result = {field: value for field, value in payload.items() if field != "status"}
|
|
682
|
+
for alias, source in control_data.get("aliases", {}).items():
|
|
683
|
+
if source in result:
|
|
684
|
+
result[alias] = result[source]
|
|
685
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Packaged CaptchaAI provider metadata."""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"RecaptchaV2TaskProxyless": {"profile": "recaptcha-v2", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "apiDomain": "domain", "recaptchaDataSValue": "data-s", "cookies": "cookies", "userAgent": "userAgent", "isInvisible": "invisible"}, "bool_int": ["isInvisible"]},
|
|
3
|
+
"RecaptchaV2Task": {"profile": "recaptcha-v2", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "apiDomain": "domain", "recaptchaDataSValue": "data-s", "cookies": "cookies", "userAgent": "userAgent", "isInvisible": "invisible"}, "bool_int": ["isInvisible"], "proxy": true},
|
|
4
|
+
"RecaptchaV2EnterpriseTaskProxyless": {"profile": "recaptcha-v2-enterprise", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "cookies": "cookies", "userAgent": "userAgent"}},
|
|
5
|
+
"RecaptchaV2EnterpriseTask": {"profile": "recaptcha-v2-enterprise", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "cookies": "cookies", "userAgent": "userAgent"}, "proxy": true},
|
|
6
|
+
"RecaptchaV3TaskProxyless": {"profile": "recaptcha-v3", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "pageAction": "action", "apiDomain": "domain", "recaptchaDataSValue": "data-s", "cookies": "cookies", "userAgent": "userAgent"}},
|
|
7
|
+
"RecaptchaV3EnterpriseTaskProxyless": {"profile": "recaptcha-v3-enterprise", "fields": {"websiteKey": "googlekey", "websiteURL": "pageurl", "pageAction": "action", "cookies": "cookies", "userAgent": "userAgent"}},
|
|
8
|
+
"TurnstileTaskProxyless": {"profile": "turnstile", "fields": {"websiteKey": "sitekey", "websiteURL": "pageurl", "action": "action"}},
|
|
9
|
+
"TurnstileTask": {"profile": "turnstile", "fields": {"websiteKey": "sitekey", "websiteURL": "pageurl", "action": "action"}, "proxy": true},
|
|
10
|
+
"ImageToTextTask": {"profile": "normal-base64", "fields": {"body": "body"}},
|
|
11
|
+
"GeeTestTask": {"profile": "geetest-v3", "fields": {"websiteURL": "pageurl", "gt": "gt", "challenge": "challenge", "userAgent": "userAgent"}},
|
|
12
|
+
"GeeTestTaskProxyless": {"profile": "geetest-v3", "fields": {"websiteURL": "pageurl", "gt": "gt", "challenge": "challenge", "userAgent": "userAgent"}},
|
|
13
|
+
"FriendlyCaptchaTask": {"profile": "friendly-captcha", "fields": {"websiteURL": "pageurl", "websiteKey": "sitekey"}, "proxy": true},
|
|
14
|
+
"FriendlyCaptchaTaskProxyless": {"profile": "friendly-captcha", "fields": {"websiteURL": "pageurl", "websiteKey": "sitekey"}},
|
|
15
|
+
"LeminTask": {"profile": "lemin", "fields": {"websiteURL": "pageurl", "captchaId": "captcha_id", "div_id": "div_id"}},
|
|
16
|
+
"LeminTaskProxyless": {"profile": "lemin", "fields": {"websiteURL": "pageurl", "captchaId": "captcha_id", "div_id": "div_id"}},
|
|
17
|
+
"CaptchaFoxTask": {"profile": "captchafox", "fields": {"websiteURL": "pageurl", "websiteKey": "sitekey", "userAgent": "userAgent"}, "proxy": true},
|
|
18
|
+
"GridTask": {"profile": "grid-base64", "fields": {"body": "body", "comment": "instructions", "grid_size": "grid_size"}}
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"profiles": {
|
|
3
|
+
"normal-base64": {"method": "base64", "required": ["body"], "aliases": {"text": "request"}},
|
|
4
|
+
"normal-file": {"method": "post", "required": ["file"], "file_fields": ["file"], "aliases": {"text": "request"}},
|
|
5
|
+
"normal-solve-base64": {"method": "base64", "required": ["body"], "submit_path": "/solve.php", "poll": false, "aliases": {"text": "request"}},
|
|
6
|
+
"normal-solve-file": {"method": "post", "required": ["file"], "file_fields": ["file"], "submit_path": "/solve.php", "poll": false, "aliases": {"text": "request"}},
|
|
7
|
+
"grid-base64": {"method": "base64", "required": ["body", "instructions", "grid_size"], "defaults": {"img_type": "recaptcha"}, "aliases": {"click": "request"}},
|
|
8
|
+
"grid-file": {"method": "post", "required": ["file", "instructions", "grid_size"], "file_fields": ["file"], "defaults": {"img_type": "recaptcha"}, "aliases": {"click": "request"}},
|
|
9
|
+
"recaptcha-v2": {"method": "userrecaptcha", "required": ["googlekey", "pageurl"], "aliases": {"token": "request", "gRecaptchaResponse": "request"}},
|
|
10
|
+
"recaptcha-v2-invisible": {"method": "userrecaptcha", "required": ["googlekey", "pageurl", "invisible"], "defaults": {"invisible": 1}, "aliases": {"token": "request", "gRecaptchaResponse": "request"}},
|
|
11
|
+
"recaptcha-v2-enterprise": {"method": "userrecaptcha", "required": ["googlekey", "pageurl", "enterprise"], "defaults": {"enterprise": 1}, "aliases": {"token": "result", "gRecaptchaResponse": "result"}},
|
|
12
|
+
"recaptcha-v3": {"method": "userrecaptcha", "required": ["googlekey", "pageurl", "version"], "defaults": {"version": "v3"}, "aliases": {"token": "request", "gRecaptchaResponse": "request"}},
|
|
13
|
+
"recaptcha-v3-enterprise": {"method": "userrecaptcha", "required": ["googlekey", "pageurl", "version", "enterprise"], "defaults": {"version": "v3", "enterprise": 1}, "aliases": {"token": "result", "gRecaptchaResponse": "result"}},
|
|
14
|
+
"turnstile": {"method": "turnstile", "required": ["sitekey", "pageurl"], "aliases": {"token": "request", "gRecaptchaResponse": "request"}},
|
|
15
|
+
"geetest-v3": {"method": "geetest", "required": ["gt", "challenge", "pageurl"], "success_fields": ["challenge", "validate", "seccode"]},
|
|
16
|
+
"friendly-captcha": {"method": "friendly_captcha", "required": ["pageurl", "sitekey"], "aliases": {"token": "request"}},
|
|
17
|
+
"lemin": {"method": "lemin", "required": ["pageurl", "captcha_id"], "aliases": {"token": "request"}},
|
|
18
|
+
"captchafox": {"method": "captchafox", "required": ["pageurl", "sitekey", "proxy", "proxytype"], "aliases": {"token": "request"}},
|
|
19
|
+
"cloudflare-challenge": {"method": "cloudflare_challenge", "required": ["pageurl", "proxy", "proxytype"], "aliases": {"cf_clearance": "result"}},
|
|
20
|
+
"bls": {"method": "bls", "required": ["instructions", "image_base64_1", "image_base64_2", "image_base64_3", "image_base64_4", "image_base64_5", "image_base64_6", "image_base64_7", "image_base64_8", "image_base64_9"], "aliases": {"click": "request"}}
|
|
21
|
+
},
|
|
22
|
+
"controls": {
|
|
23
|
+
"balance": {"action": "getbalance", "aliases": {"balance": "request"}},
|
|
24
|
+
"threads_info": {"action": "threadsinfo"}
|
|
25
|
+
}
|
|
26
|
+
}
|
python_rucaptcha/core/enums.py
CHANGED
|
@@ -24,6 +24,7 @@ class ServiceEnm(str, MyEnum):
|
|
|
24
24
|
TWOCAPTCHA = "2captcha"
|
|
25
25
|
RUCAPTCHA = "rucaptcha"
|
|
26
26
|
DEATHBYCAPTCHA = "deathbycaptcha"
|
|
27
|
+
CAPTCHAAI = "captchaai"
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
class SaveFormatsEnm(str, MyEnum):
|
|
@@ -58,6 +59,7 @@ class ReCaptchaEnm(str, MyEnum):
|
|
|
58
59
|
RecaptchaV2EnterpriseTask = "RecaptchaV2EnterpriseTask"
|
|
59
60
|
|
|
60
61
|
RecaptchaV3TaskProxyless = "RecaptchaV3TaskProxyless"
|
|
62
|
+
RecaptchaV3EnterpriseTaskProxyless = "RecaptchaV3EnterpriseTaskProxyless"
|
|
61
63
|
|
|
62
64
|
|
|
63
65
|
class LeminCaptchaEnm(str, MyEnum):
|
|
@@ -68,7 +68,11 @@ class CaptchaOptionsSer(MyBaseModel):
|
|
|
68
68
|
if isinstance(self.service_type, enums.ServiceEnm):
|
|
69
69
|
self.service_type = self.service_type.value
|
|
70
70
|
|
|
71
|
-
if self.service_type == enums.ServiceEnm.
|
|
71
|
+
if self.service_type == enums.ServiceEnm.CAPTCHAAI:
|
|
72
|
+
# CaptchaAI exposes the classic 2captcha in.php/res.php API.
|
|
73
|
+
self.url_request = "https://ocr.captchaai.com/in.php"
|
|
74
|
+
self.url_response = "https://ocr.captchaai.com/res.php"
|
|
75
|
+
elif self.service_type == enums.ServiceEnm.DEATHBYCAPTCHA:
|
|
72
76
|
self.url_request = f"http://api.{self.service_type}.com/2captcha/in.php"
|
|
73
77
|
self.url_response = f"http://api.{self.service_type}.com/2captcha/res.php"
|
|
74
78
|
else:
|
|
@@ -83,13 +87,13 @@ HTTP API Response
|
|
|
83
87
|
|
|
84
88
|
class GetTaskResultResponseSer(MyBaseModel):
|
|
85
89
|
status: str = "ready"
|
|
86
|
-
solution: dict[str,
|
|
90
|
+
solution: dict[str, Any] | None = None
|
|
87
91
|
cost: float = 0.0
|
|
88
92
|
ip: str | None = None
|
|
89
93
|
createTime: int | None = None
|
|
90
94
|
endTime: int | None = None
|
|
91
95
|
solveCount: int | None = None
|
|
92
|
-
taskId: int | None = None
|
|
96
|
+
taskId: int | str | None = None
|
|
93
97
|
# control method params
|
|
94
98
|
balance: float | None = None
|
|
95
99
|
# error info
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-rucaptcha
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.7.0
|
|
4
4
|
Summary: Python 3.9+ RuCaptcha library with AIO module.
|
|
5
5
|
Author-email: AndreiDrang <python-captcha@pm.me>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -39,7 +39,63 @@ Dynamic: license-file
|
|
|
39
39
|
[](https://pepy.tech/project/python-rucaptcha)
|
|
40
40
|
[](https://andreidrang.github.io/python-rucaptcha/)
|
|
41
41
|
|
|
42
|
-
**Python 3.9+ library to solve CAPTCHAs automatically using RuCaptcha, 2Captcha, or
|
|
42
|
+
**Python 3.9+ library to solve CAPTCHAs automatically using RuCaptcha, 2Captcha, DeathByCaptcha, or CaptchaAI services.**
|
|
43
|
+
|
|
44
|
+
> **Using CaptchaAI:** compatible high-level classes can pass `service_type=ServiceEnm.CAPTCHAAI`.
|
|
45
|
+
> CaptchaAI uses the classic multipart `in.php`/`res.php` endpoints.
|
|
46
|
+
> ```python
|
|
47
|
+
> from python_rucaptcha.turnstile import Turnstile
|
|
48
|
+
> from python_rucaptcha.core.enums import ServiceEnm
|
|
49
|
+
> result = Turnstile(
|
|
50
|
+
> rucaptcha_key="CAPTCHAAI_KEY",
|
|
51
|
+
> service_type=ServiceEnm.CAPTCHAAI,
|
|
52
|
+
> websiteURL="https://example.com",
|
|
53
|
+
> websiteKey="0x4AAAAAAA...",
|
|
54
|
+
> userAgent="Mozilla/5.0 ...",
|
|
55
|
+
> ).captcha_handler()
|
|
56
|
+
> ```
|
|
57
|
+
>
|
|
58
|
+
> Proxy task types require `proxyType`, `proxyAddress`, and `proxyPort`; credentials are optional:
|
|
59
|
+
> ```python
|
|
60
|
+
> from python_rucaptcha.re_captcha import ReCaptcha
|
|
61
|
+
> from python_rucaptcha.core.enums import ReCaptchaEnm, ServiceEnm
|
|
62
|
+
>
|
|
63
|
+
> result = ReCaptcha(
|
|
64
|
+
> rucaptcha_key="CAPTCHAAI_KEY",
|
|
65
|
+
> service_type=ServiceEnm.CAPTCHAAI,
|
|
66
|
+
> websiteURL="https://example.com/login",
|
|
67
|
+
> websiteKey="SITE_KEY",
|
|
68
|
+
> method=ReCaptchaEnm.RecaptchaV2Task,
|
|
69
|
+
> proxyType="HTTPS",
|
|
70
|
+
> proxyAddress="203.0.113.7",
|
|
71
|
+
> proxyPort=3128,
|
|
72
|
+
> proxyLogin="user",
|
|
73
|
+
> proxyPassword="pass",
|
|
74
|
+
> ).captcha_handler()
|
|
75
|
+
> ```
|
|
76
|
+
>
|
|
77
|
+
> For every documented CaptchaAI method—or a provider method released after this package—use the native,
|
|
78
|
+
> type-free client. `profile` validates a packaged documented contract; omit it to pass provider-native fields
|
|
79
|
+
> through unchanged.
|
|
80
|
+
> ```python
|
|
81
|
+
> from python_rucaptcha.captchaai import CaptchaAI, CaptchaAIFile
|
|
82
|
+
>
|
|
83
|
+
> result = CaptchaAI(
|
|
84
|
+
> rucaptcha_key="CAPTCHAAI_KEY",
|
|
85
|
+
> profile="cloudflare-challenge",
|
|
86
|
+
> params={
|
|
87
|
+
> "pageurl": "https://example.com/protected",
|
|
88
|
+
> "proxy": "user:pass@203.0.113.7:3128",
|
|
89
|
+
> "proxytype": "HTTPS",
|
|
90
|
+
> },
|
|
91
|
+
> ).captcha_handler()
|
|
92
|
+
>
|
|
93
|
+
> image = CaptchaAI(
|
|
94
|
+
> rucaptcha_key="CAPTCHAAI_KEY",
|
|
95
|
+
> profile="normal-solve-file",
|
|
96
|
+
> files={"file": CaptchaAIFile(b"... PNG bytes ...", "captcha.png", "image/png")},
|
|
97
|
+
> ).captcha_handler()
|
|
98
|
+
> ```
|
|
43
99
|
|
|
44
100
|
## What is this?
|
|
45
101
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
python_rucaptcha/__init__.py,sha256=odkQWtwx2RgIjD8pw2ZF-KR-5nL0Yu2Wn7Mu2YdBrSk,61
|
|
2
|
-
python_rucaptcha/__version__.py,sha256=
|
|
2
|
+
python_rucaptcha/__version__.py,sha256=Pir-5w3irbzZXGeqJXmdurth8wAFGTbSTHVO2zC-Nng,22
|
|
3
3
|
python_rucaptcha/altcha_captcha.py,sha256=ZZdNUWikyC5LTGCSVnqSrmmgw6TSfRcp44CagBBOHsE,5146
|
|
4
4
|
python_rucaptcha/amazon_waf.py,sha256=psEg-sym8xQlMPPto1ND_HE0vGV_SRRrDnsKuEbbxNA,3625
|
|
5
5
|
python_rucaptcha/atb_captcha.py,sha256=FuGG9MKTy7f_Sku7WQLZ7TCZ1ISFnu_0h4I3_Qri8JQ,3724
|
|
@@ -7,6 +7,7 @@ python_rucaptcha/audio_captcha.py,sha256=Bp6-gF3cTnYL8aeY8k4D4Ii7zPqy1Qo2OFRooSE
|
|
|
7
7
|
python_rucaptcha/binance_captcha.py,sha256=7RlhY0ZUMcQkBt7y03vCx6lOllH5PxoxYAoB2R4T3RE,5760
|
|
8
8
|
python_rucaptcha/bounding_box_captcha.py,sha256=JvJEU1Y0A1SVkJV9jEFgBQ7Nis-vFkTmfUBoHIeTinY,10648
|
|
9
9
|
python_rucaptcha/captcha_fox.py,sha256=sm2cusbBYeOtMMZmZn51o0rtX8SQzPR_6oYmUSVWTCc,4101
|
|
10
|
+
python_rucaptcha/captchaai.py,sha256=aHMErwl_b4ImPbWsYpxnZ98Cfv7-HAatzlQWsbuBkt4,5929
|
|
10
11
|
python_rucaptcha/capy_puzzle.py,sha256=ITr1HNALlaKtBkrBht2QtEtP-u6K4-JXpDKKwih7RhA,4973
|
|
11
12
|
python_rucaptcha/control.py,sha256=1KnPaUOVEU7DY6x9-CJvuyV8nFapBcxGRfE9y3dprTo,4993
|
|
12
13
|
python_rucaptcha/coordinates_captcha.py,sha256=lmotaD_dOzo2T9MdcaOgQdB5opL-Hs-ZVUW5nTy-KJ0,9911
|
|
@@ -34,13 +35,17 @@ python_rucaptcha/vk_captcha.py,sha256=SiyywA2o62mbk9IWHalUIzALaeZTqoQ1nEwirLBbfd
|
|
|
34
35
|
python_rucaptcha/yandex_smart_captcha.py,sha256=V21WQdDND0r0FAmYN9zYpBeKuna20PsdMsqgCuGGlPI,10237
|
|
35
36
|
python_rucaptcha/yidun_captcha.py,sha256=aLpddgc-beVe_x0Ts028Jgg1uk_DQhSQGU7fh_dYkVM,6612
|
|
36
37
|
python_rucaptcha/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
-
python_rucaptcha/core/base.py,sha256=
|
|
38
|
+
python_rucaptcha/core/base.py,sha256=txm-eSmICDfXCShstYX5ojAZ2OJLe4FyeZmbbopTMXM,11680
|
|
39
|
+
python_rucaptcha/core/captchaai.py,sha256=5Kh2dGfTL_3tMdBH3khq38H3q9KqLud8szaSwhL01Aw,23764
|
|
38
40
|
python_rucaptcha/core/config.py,sha256=ocoPeMXfn-2iqaqcjewZWfRpu73D5dY2AL2zqXVrG9Q,613
|
|
39
|
-
python_rucaptcha/core/enums.py,sha256=
|
|
41
|
+
python_rucaptcha/core/enums.py,sha256=cKEOcpnou0CbAFz2c6SoedfSSdG0DcgsnmTn-dm-R7I,4794
|
|
40
42
|
python_rucaptcha/core/result_handler.py,sha256=CkltxRgRsG6xkcRPcbCUZHRl-XXvyCtWJ6aZshe3WYA,5076
|
|
41
|
-
python_rucaptcha/core/serializer.py,sha256=
|
|
42
|
-
python_rucaptcha
|
|
43
|
-
python_rucaptcha
|
|
44
|
-
python_rucaptcha
|
|
45
|
-
python_rucaptcha-6.
|
|
46
|
-
python_rucaptcha-6.
|
|
43
|
+
python_rucaptcha/core/serializer.py,sha256=TFYkV6Feq_FTo7NqTpTo_jzKj2aGYKg5CztMTTHouwQ,2970
|
|
44
|
+
python_rucaptcha/core/data/__init__.py,sha256=_DueAqmAAsgx7F2zYG_3_UoR8oJRNg9Xu4Tczn0f0bo,44
|
|
45
|
+
python_rucaptcha/core/data/captchaai_legacy_profiles.json,sha256=GkNDw4q9hTnkoL0XpsWh0oVzkBwSRVEXigRg7f05MN0,2878
|
|
46
|
+
python_rucaptcha/core/data/captchaai_profiles.json,sha256=bzxmOTWr-pzVeE2NpdXZRywLs20bGcaGY7HYszqQ5qY,3097
|
|
47
|
+
python_rucaptcha-6.7.0.dist-info/licenses/LICENSE,sha256=ZQeZG4IrO4YywdTal32gqyyrwdMlrMa3EwJCbgM8b2k,1063
|
|
48
|
+
python_rucaptcha-6.7.0.dist-info/METADATA,sha256=XuK_fYkfm_kN-R3ixh7JFsmPM8owbmKAIs33iHlOj9U,8395
|
|
49
|
+
python_rucaptcha-6.7.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
50
|
+
python_rucaptcha-6.7.0.dist-info/top_level.txt,sha256=Eu_atEB79Y7jCsfXPcXF5N8OLt6kKVbvhuRsI1BmSWM,17
|
|
51
|
+
python_rucaptcha-6.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|