capmonster-python 5.0.0__py3-none-any.whl → 5.1.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.
- capmonster_python/__init__.py +15 -0
- capmonster_python/_deprecation.py +24 -0
- capmonster_python/client.py +96 -14
- capmonster_python/methods.py +20 -0
- capmonster_python/tasks/__init__.py +21 -2
- capmonster_python/tasks/alibaba.py +69 -0
- capmonster_python/tasks/arcaptcha.py +23 -0
- capmonster_python/tasks/castle.py +7 -0
- capmonster_python/tasks/complex_image_recognition.py +30 -6
- capmonster_python/tasks/datadome.py +8 -0
- capmonster_python/tasks/fengkongcloud.py +39 -0
- capmonster_python/tasks/friendly.py +43 -0
- capmonster_python/tasks/funcaptcha.py +5 -0
- capmonster_python/tasks/heytap.py +40 -0
- capmonster_python/tasks/hunt.py +59 -6
- capmonster_python/tasks/imperva.py +40 -7
- capmonster_python/tasks/proton.py +40 -0
- capmonster_python/tasks/recaptcha_click.py +8 -0
- capmonster_python/tasks/recaptcha_v2_enterprise.py +2 -0
- capmonster_python/tasks/temu.py +7 -0
- capmonster_python/tasks/tendi.py +18 -2
- capmonster_python/tasks/turnstile.py +5 -7
- {capmonster_python-5.0.0.dist-info → capmonster_python-5.1.0.dist-info}/METADATA +25 -10
- capmonster_python-5.1.0.dist-info/RECORD +43 -0
- {capmonster_python-5.0.0.dist-info → capmonster_python-5.1.0.dist-info}/WHEEL +1 -1
- capmonster_python-5.0.0.dist-info/RECORD +0 -36
- {capmonster_python-5.0.0.dist-info → capmonster_python-5.1.0.dist-info}/licenses/LICENSE +0 -0
- {capmonster_python-5.0.0.dist-info → capmonster_python-5.1.0.dist-info}/top_level.txt +0 -0
capmonster_python/__init__.py
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
from .client import CapmonsterClient
|
|
2
|
+
from .methods import TaskResult
|
|
2
3
|
from .exceptions import *
|
|
3
4
|
from .tasks import *
|
|
4
5
|
|
|
5
6
|
__all__ = [
|
|
6
7
|
"CapmonsterClient",
|
|
8
|
+
"TaskResult",
|
|
7
9
|
"VanillaTaskPayload",
|
|
8
10
|
"ProxyPayload",
|
|
9
11
|
"UserAgentPayload",
|
|
12
|
+
"AlibabaTask",
|
|
13
|
+
"AlibabaMetadata",
|
|
10
14
|
"AltchaTask",
|
|
11
15
|
"AltchaMetadata",
|
|
12
16
|
"AmazonTask",
|
|
17
|
+
"ARCaptchaTask",
|
|
13
18
|
"BasiliskTask",
|
|
14
19
|
"BinanceTask",
|
|
15
20
|
"CastleTask",
|
|
@@ -19,15 +24,24 @@ __all__ = [
|
|
|
19
24
|
"ComplexImageRecognitionTask",
|
|
20
25
|
"DataDomeTask",
|
|
21
26
|
"DataDomeMetadata",
|
|
27
|
+
"FengkongCloudTask",
|
|
28
|
+
"FengkongCloudMetadata",
|
|
29
|
+
"FriendlyTask",
|
|
30
|
+
"FriendlyMetadata",
|
|
22
31
|
"FunCaptchaTask",
|
|
23
32
|
"GeeTestV3Task",
|
|
24
33
|
"GeeTestV4Task",
|
|
34
|
+
"HeyTapTask",
|
|
35
|
+
"HeyTapMetadata",
|
|
25
36
|
"HuntTask",
|
|
37
|
+
"HuntMetadata",
|
|
26
38
|
"ImageToTextTask",
|
|
27
39
|
"ImpervaTask",
|
|
28
40
|
"ImpervaTaskMetadata",
|
|
29
41
|
"MTCaptchaTask",
|
|
30
42
|
"ProsopoTask",
|
|
43
|
+
"ProtonTask",
|
|
44
|
+
"ProtonMetadata",
|
|
31
45
|
"RecaptchaClickTask",
|
|
32
46
|
"RecaptchaV2Task",
|
|
33
47
|
"RecaptchaV2EnterpriseTask",
|
|
@@ -35,6 +49,7 @@ __all__ = [
|
|
|
35
49
|
"RecaptchaV3EnterpriseTask",
|
|
36
50
|
"TemuTask",
|
|
37
51
|
"TenDITask",
|
|
52
|
+
"TenDIMetadata",
|
|
38
53
|
"TSPDTask",
|
|
39
54
|
"TSPDMetadata",
|
|
40
55
|
"TurnstileTask",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def warn_deprecated(message: str, stacklevel: int = 3) -> None:
|
|
5
|
+
"""
|
|
6
|
+
Emits a DeprecationWarning pointing at the caller's code.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
message: What is deprecated and what to use instead.
|
|
10
|
+
stacklevel: How many frames up the warning should point to.
|
|
11
|
+
"""
|
|
12
|
+
warnings.warn(message, DeprecationWarning, stacklevel=stacklevel)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def warn_proxy_required(task: str, stacklevel: int = 3) -> None:
|
|
16
|
+
"""
|
|
17
|
+
Emits a UserWarning when a task that the API documents as proxy-only is created without a proxy.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
task: Name of the task class.
|
|
21
|
+
stacklevel: How many frames up the warning should point to.
|
|
22
|
+
"""
|
|
23
|
+
warnings.warn(f"{task}: CapMonster Cloud requires your own proxy for this task; "
|
|
24
|
+
f"the request will likely be rejected without one.", UserWarning, stacklevel=stacklevel)
|
capmonster_python/client.py
CHANGED
|
@@ -5,7 +5,8 @@ from typing import Optional
|
|
|
5
5
|
from httpx import Response, AsyncClient, Client
|
|
6
6
|
|
|
7
7
|
from .exceptions import CapmonsterAPIException, CapmonsterException
|
|
8
|
-
from .methods import GetBalancePayload, GetTaskResultPayload, CreateTaskPayload, ReportIncorrectCaptchaPayload
|
|
8
|
+
from .methods import GetBalancePayload, GetTaskResultPayload, CreateTaskPayload, ReportIncorrectCaptchaPayload, \
|
|
9
|
+
TaskResult
|
|
9
10
|
from .tasks.task import TaskPayload
|
|
10
11
|
|
|
11
12
|
|
|
@@ -140,9 +141,22 @@ class CapmonsterClient:
|
|
|
140
141
|
result API endpoint. If the solution is not found in the response, an empty
|
|
141
142
|
dictionary is returned.
|
|
142
143
|
"""
|
|
144
|
+
return self.get_task_result_detailed(task_id).solution
|
|
145
|
+
|
|
146
|
+
def get_task_result_detailed(self, task_id: int) -> TaskResult:
|
|
147
|
+
"""
|
|
148
|
+
Fetches the full result of a specific task by its identifier, including its status and cost.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
task_id (int): An integer representing the unique identifier of the task.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
TaskResult: The status, solution and cost of the task. The solution is an empty
|
|
155
|
+
dictionary and the cost is None while the task is processing.
|
|
156
|
+
"""
|
|
143
157
|
payload = GetTaskResultPayload(clientKey=self.api_key, taskId=task_id).model_dump()
|
|
144
158
|
response = self.__make_sync_request(self.__TASK_RESULT_URL, payload).json()
|
|
145
|
-
return
|
|
159
|
+
return TaskResult.from_response(response)
|
|
146
160
|
|
|
147
161
|
async def get_task_result_async(self, task_id: int) -> dict:
|
|
148
162
|
"""
|
|
@@ -162,10 +176,22 @@ class CapmonsterClient:
|
|
|
162
176
|
result API endpoint. If the solution is not found in the response, an empty
|
|
163
177
|
dictionary is returned.
|
|
164
178
|
"""
|
|
179
|
+
return (await self.get_task_result_detailed_async(task_id)).solution
|
|
180
|
+
|
|
181
|
+
async def get_task_result_detailed_async(self, task_id: int) -> TaskResult:
|
|
182
|
+
"""
|
|
183
|
+
Asynchronously fetches the full result of a specific task by its identifier, including its status and cost.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
task_id (int): An integer representing the unique identifier of the task.
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
TaskResult: The status, solution and cost of the task. The solution is an empty
|
|
190
|
+
dictionary and the cost is None while the task is processing.
|
|
191
|
+
"""
|
|
165
192
|
payload = GetTaskResultPayload(clientKey=self.api_key, taskId=task_id).model_dump()
|
|
166
193
|
request = await self.__make_async_request(self.__TASK_RESULT_URL, payload)
|
|
167
|
-
|
|
168
|
-
return response.get("solution", {})
|
|
194
|
+
return TaskResult.from_response(request.json())
|
|
169
195
|
|
|
170
196
|
def join_task_result(self, task_id: int) -> dict:
|
|
171
197
|
"""
|
|
@@ -179,16 +205,31 @@ class CapmonsterClient:
|
|
|
179
205
|
dict:
|
|
180
206
|
The result of the task if successfully retrieved within the maximum retries.
|
|
181
207
|
|
|
208
|
+
Raises:
|
|
209
|
+
CapmonsterException:
|
|
210
|
+
If the maximum retry limit is exceeded without obtaining the task result.
|
|
211
|
+
"""
|
|
212
|
+
return self.join_task_result_detailed(task_id).solution
|
|
213
|
+
|
|
214
|
+
def join_task_result_detailed(self, task_id: int) -> TaskResult:
|
|
215
|
+
"""
|
|
216
|
+
Polls the result of a task like `join_task_result`, but returns its status and cost too.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
task_id: The identifier of the task for which the result needs to be retrieved.
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
TaskResult: The status, solution and cost of the completed task.
|
|
223
|
+
|
|
182
224
|
Raises:
|
|
183
225
|
CapmonsterException:
|
|
184
226
|
If the maximum retry limit is exceeded without obtaining the task result.
|
|
185
227
|
"""
|
|
186
228
|
for _ in range(0, self.__max_retries + 1):
|
|
187
|
-
result = self.
|
|
188
|
-
if result:
|
|
229
|
+
result = self.get_task_result_detailed(task_id)
|
|
230
|
+
if result.solution:
|
|
189
231
|
return result
|
|
190
|
-
|
|
191
|
-
sleep(self.__retry_delay)
|
|
232
|
+
sleep(self.__retry_delay)
|
|
192
233
|
raise CapmonsterAPIException(
|
|
193
234
|
61, "ERROR_MAXIMUM_TIME_EXCEED", "Maximum time is exceed.")
|
|
194
235
|
|
|
@@ -204,16 +245,31 @@ class CapmonsterClient:
|
|
|
204
245
|
dict:
|
|
205
246
|
The result of the task if successfully retrieved within the maximum retries.
|
|
206
247
|
|
|
248
|
+
Raises:
|
|
249
|
+
CapmonsterException:
|
|
250
|
+
If the maximum retry limit is exceeded without obtaining the task result.
|
|
251
|
+
"""
|
|
252
|
+
return (await self.join_task_result_detailed_async(task_id)).solution
|
|
253
|
+
|
|
254
|
+
async def join_task_result_detailed_async(self, task_id: int) -> TaskResult:
|
|
255
|
+
"""
|
|
256
|
+
Asynchronously polls the result of a task like `join_task_result_async`, but returns its status and cost too.
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
task_id: The identifier of the task for which the result needs to be retrieved.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
TaskResult: The status, solution and cost of the completed task.
|
|
263
|
+
|
|
207
264
|
Raises:
|
|
208
265
|
CapmonsterException:
|
|
209
266
|
If the maximum retry limit is exceeded without obtaining the task result.
|
|
210
267
|
"""
|
|
211
268
|
for _ in range(0, self.__max_retries + 1):
|
|
212
|
-
result = await self.
|
|
213
|
-
if result:
|
|
269
|
+
result = await self.get_task_result_detailed_async(task_id)
|
|
270
|
+
if result.solution:
|
|
214
271
|
return result
|
|
215
|
-
|
|
216
|
-
await asyncio.sleep(self.__retry_delay)
|
|
272
|
+
await asyncio.sleep(self.__retry_delay)
|
|
217
273
|
raise CapmonsterAPIException(
|
|
218
274
|
61, "ERROR_MAXIMUM_TIME_EXCEED", "Maximum time is exceed.")
|
|
219
275
|
|
|
@@ -230,8 +286,21 @@ class CapmonsterClient:
|
|
|
230
286
|
Returns:
|
|
231
287
|
dict: The solution dictionary from the completed task.
|
|
232
288
|
"""
|
|
289
|
+
return self.solve_detailed(task, callback_url).solution
|
|
290
|
+
|
|
291
|
+
def solve_detailed(self, task: TaskPayload, callback_url: Optional[str] = None) -> TaskResult:
|
|
292
|
+
"""
|
|
293
|
+
Creates a task and polls for its result like `solve`, but returns its status and cost too.
|
|
294
|
+
|
|
295
|
+
Args:
|
|
296
|
+
task: The task configuration payload.
|
|
297
|
+
callback_url: An optional callback URL for task completion.
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
TaskResult: The status, solution and cost of the completed task.
|
|
301
|
+
"""
|
|
233
302
|
task_id = self.create_task(task, callback_url)
|
|
234
|
-
return self.
|
|
303
|
+
return self.join_task_result_detailed(task_id)
|
|
235
304
|
|
|
236
305
|
async def solve_async(self, task: TaskPayload, callback_url: Optional[str] = None) -> dict:
|
|
237
306
|
"""
|
|
@@ -246,8 +315,21 @@ class CapmonsterClient:
|
|
|
246
315
|
Returns:
|
|
247
316
|
dict: The solution dictionary from the completed task.
|
|
248
317
|
"""
|
|
318
|
+
return (await self.solve_detailed_async(task, callback_url)).solution
|
|
319
|
+
|
|
320
|
+
async def solve_detailed_async(self, task: TaskPayload, callback_url: Optional[str] = None) -> TaskResult:
|
|
321
|
+
"""
|
|
322
|
+
Async version of `solve_detailed`: creates a task and polls for its result, including its status and cost.
|
|
323
|
+
|
|
324
|
+
Args:
|
|
325
|
+
task: The task configuration payload.
|
|
326
|
+
callback_url: An optional callback URL for task completion.
|
|
327
|
+
|
|
328
|
+
Returns:
|
|
329
|
+
TaskResult: The status, solution and cost of the completed task.
|
|
330
|
+
"""
|
|
249
331
|
task_id = await self.create_task_async(task, callback_url)
|
|
250
|
-
return await self.
|
|
332
|
+
return await self.join_task_result_detailed_async(task_id)
|
|
251
333
|
|
|
252
334
|
def report_incorrect_image(self, task_id: int) -> None:
|
|
253
335
|
"""
|
capmonster_python/methods.py
CHANGED
|
@@ -35,3 +35,23 @@ class CreateTaskPayload(BaseModel):
|
|
|
35
35
|
@field_serializer("task")
|
|
36
36
|
def serialize_task(self, task: TaskPayload, _info) -> dict:
|
|
37
37
|
return task.to_request()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TaskResult(BaseModel):
|
|
41
|
+
"""
|
|
42
|
+
Represents the full result of a task returned by getTaskResult.
|
|
43
|
+
|
|
44
|
+
Attributes:
|
|
45
|
+
status (str): "processing" while the task is being solved, "ready" when it is done.
|
|
46
|
+
solution (dict): The solution of the task; empty while the task is processing.
|
|
47
|
+
cost (Optional[float]): Cost of the task in USD; only returned when the task is ready.
|
|
48
|
+
"""
|
|
49
|
+
status: str = Field(default="processing", description="Task status: processing or ready.")
|
|
50
|
+
solution: dict = Field(default_factory=dict, description="Task solution.")
|
|
51
|
+
cost: Optional[float] = Field(default=None, description="Cost of the task in USD.")
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_response(cls, response: dict) -> "TaskResult":
|
|
55
|
+
return cls(status=response.get("status") or "processing",
|
|
56
|
+
solution=response.get("solution") or {},
|
|
57
|
+
cost=response.get("cost"))
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
from .alibaba import AlibabaTask, AlibabaMetadata
|
|
1
2
|
from .altcha import AltchaTask, AltchaMetadata
|
|
2
3
|
from .amazon import AmazonTask
|
|
4
|
+
from .arcaptcha import ARCaptchaTask
|
|
3
5
|
from .basilisk import BasiliskTask
|
|
4
6
|
from .binance import BinanceTask
|
|
5
7
|
from .castle import CastleTask, CastleMetadata
|
|
6
8
|
from .complex_image_recaptcha import ComplexImageRecaptchaTask, ComplexImageRecaptchaMetadata
|
|
7
9
|
from .complex_image_recognition import ComplexImageRecognitionTask
|
|
8
10
|
from .datadome import DataDomeTask, DataDomeMetadata
|
|
11
|
+
from .fengkongcloud import FengkongCloudTask, FengkongCloudMetadata
|
|
12
|
+
from .friendly import FriendlyTask, FriendlyMetadata
|
|
9
13
|
from .funcaptcha import FunCaptchaTask
|
|
10
14
|
from .geetest import GeeTestV4Task, GeeTestV3Task
|
|
11
|
-
from .
|
|
15
|
+
from .heytap import HeyTapTask, HeyTapMetadata
|
|
16
|
+
from .hunt import HuntTask, HuntMetadata
|
|
12
17
|
from .image_to_text import ImageToTextTask
|
|
13
18
|
from .imperva import ImpervaTask, ImpervaTaskMetadata
|
|
14
19
|
from .mtcaptcha import MTCaptchaTask
|
|
15
20
|
from .prosopo import ProsopoTask
|
|
21
|
+
from .proton import ProtonTask, ProtonMetadata
|
|
16
22
|
from .recaptcha_click import RecaptchaClickTask
|
|
17
23
|
from .recaptcha_v2 import RecaptchaV2Task
|
|
18
24
|
from .recaptcha_v2_enterprise import RecaptchaV2EnterpriseTask
|
|
@@ -20,7 +26,7 @@ from .recaptcha_v3 import RecaptchaV3Task
|
|
|
20
26
|
from .recaptcha_v3_enterprise import RecaptchaV3EnterpriseTask
|
|
21
27
|
from .task import VanillaTaskPayload, ProxyPayload, UserAgentPayload
|
|
22
28
|
from .temu import TemuTask
|
|
23
|
-
from .tendi import TenDITask
|
|
29
|
+
from .tendi import TenDITask, TenDIMetadata
|
|
24
30
|
from .tspd import TSPDTask, TSPDMetadata
|
|
25
31
|
from .turnstile import TurnstileTask, TurnstileCloudFlareTask, TurnstileWaitingRoomTask
|
|
26
32
|
from .yidun import YidunTask
|
|
@@ -29,9 +35,12 @@ __all__ = [
|
|
|
29
35
|
"VanillaTaskPayload",
|
|
30
36
|
"ProxyPayload",
|
|
31
37
|
"UserAgentPayload",
|
|
38
|
+
"AlibabaTask",
|
|
39
|
+
"AlibabaMetadata",
|
|
32
40
|
"AltchaTask",
|
|
33
41
|
"AltchaMetadata",
|
|
34
42
|
"AmazonTask",
|
|
43
|
+
"ARCaptchaTask",
|
|
35
44
|
"BasiliskTask",
|
|
36
45
|
"BinanceTask",
|
|
37
46
|
"CastleTask",
|
|
@@ -41,15 +50,24 @@ __all__ = [
|
|
|
41
50
|
"ComplexImageRecognitionTask",
|
|
42
51
|
"DataDomeTask",
|
|
43
52
|
"DataDomeMetadata",
|
|
53
|
+
"FengkongCloudTask",
|
|
54
|
+
"FengkongCloudMetadata",
|
|
55
|
+
"FriendlyTask",
|
|
56
|
+
"FriendlyMetadata",
|
|
44
57
|
"FunCaptchaTask",
|
|
45
58
|
"GeeTestV3Task",
|
|
46
59
|
"GeeTestV4Task",
|
|
60
|
+
"HeyTapTask",
|
|
61
|
+
"HeyTapMetadata",
|
|
47
62
|
"HuntTask",
|
|
63
|
+
"HuntMetadata",
|
|
48
64
|
"ImageToTextTask",
|
|
49
65
|
"ImpervaTask",
|
|
50
66
|
"ImpervaTaskMetadata",
|
|
51
67
|
"MTCaptchaTask",
|
|
52
68
|
"ProsopoTask",
|
|
69
|
+
"ProtonTask",
|
|
70
|
+
"ProtonMetadata",
|
|
53
71
|
"RecaptchaClickTask",
|
|
54
72
|
"RecaptchaV2Task",
|
|
55
73
|
"RecaptchaV2EnterpriseTask",
|
|
@@ -57,6 +75,7 @@ __all__ = [
|
|
|
57
75
|
"RecaptchaV3EnterpriseTask",
|
|
58
76
|
"TemuTask",
|
|
59
77
|
"TenDITask",
|
|
78
|
+
"TenDIMetadata",
|
|
60
79
|
"TSPDTask",
|
|
61
80
|
"TSPDMetadata",
|
|
62
81
|
"TurnstileTask",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, BaseModel, model_validator
|
|
4
|
+
|
|
5
|
+
from .task import TaskPayload, ProxyPayload, UserAgentPayload
|
|
6
|
+
from ..exceptions import CapmonsterValidationException
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AlibabaMetadata(BaseModel):
|
|
10
|
+
"""
|
|
11
|
+
Metadata for Alibaba task.
|
|
12
|
+
|
|
13
|
+
`sceneId` and `prefix` are required unless `punishUrl` is given. Pass the other
|
|
14
|
+
fields only if the website uses them.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
sceneId: The captcha scenario identifier.
|
|
18
|
+
prefix: Captcha initialization parameter (the subdomain of the captcha-open URL).
|
|
19
|
+
userId: Unique identifier of the user or session on the website side.
|
|
20
|
+
userUserId: Additional (secondary) user identifier.
|
|
21
|
+
verifyType: Version or type of the verification mechanism, e.g. "1.0".
|
|
22
|
+
region: Region that processes the captcha, e.g. "cn" or "sgp".
|
|
23
|
+
UserCertifyId: Verification ID of the current captcha session.
|
|
24
|
+
apiGetLib: Link to the captcha JS library used by the website.
|
|
25
|
+
punishUrl: Full URL of the /punish verification page, including its query string.
|
|
26
|
+
cookieRequired: Return cookies with the solution (for Alibaba WAF).
|
|
27
|
+
"""
|
|
28
|
+
sceneId: Optional[str] = Field(default=None, description="The captcha scenario identifier.")
|
|
29
|
+
prefix: Optional[str] = Field(default=None, description="Captcha initialization parameter.")
|
|
30
|
+
userId: Optional[str] = Field(default=None, description="User or session identifier.")
|
|
31
|
+
userUserId: Optional[str] = Field(default=None, description="Secondary user identifier.")
|
|
32
|
+
verifyType: Optional[str] = Field(default=None, description="Verification mechanism version.")
|
|
33
|
+
region: Optional[str] = Field(default=None, description="Region that processes the captcha.")
|
|
34
|
+
UserCertifyId: Optional[str] = Field(default=None, description="Verification ID of the captcha session.")
|
|
35
|
+
apiGetLib: Optional[str] = Field(default=None, description="Link to the captcha JS library.")
|
|
36
|
+
punishUrl: Optional[str] = Field(default=None, description="Full URL of the /punish verification page.")
|
|
37
|
+
cookieRequired: Optional[bool] = Field(default=None, description="Return cookies with the solution.")
|
|
38
|
+
|
|
39
|
+
@model_validator(mode="after")
|
|
40
|
+
def check_required(self) -> "AlibabaMetadata":
|
|
41
|
+
if self.punishUrl is None and (self.sceneId is None or self.prefix is None):
|
|
42
|
+
raise CapmonsterValidationException("sceneId and prefix are required unless punishUrl is set",
|
|
43
|
+
task="AlibabaTask")
|
|
44
|
+
return self
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class AlibabaTask(TaskPayload, UserAgentPayload):
|
|
48
|
+
"""
|
|
49
|
+
Represents a task for solving Alibaba captcha challenges.
|
|
50
|
+
|
|
51
|
+
Uses CustomTask type with class "alibaba".
|
|
52
|
+
|
|
53
|
+
Attributes:
|
|
54
|
+
websiteURL: Full URL of the page with the captcha.
|
|
55
|
+
metadata: Alibaba-specific metadata.
|
|
56
|
+
proxy: Optional proxy settings.
|
|
57
|
+
"""
|
|
58
|
+
type: str = Field(default="CustomTask", frozen=True)
|
|
59
|
+
class_: str = Field(default="alibaba", alias="class", frozen=True)
|
|
60
|
+
websiteURL: str = Field(..., description='Full URL of the page with the captcha.')
|
|
61
|
+
metadata: AlibabaMetadata = Field(..., description='Alibaba-specific metadata.')
|
|
62
|
+
proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
|
|
63
|
+
|
|
64
|
+
def to_request(self) -> dict[str, Any]:
|
|
65
|
+
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
66
|
+
proxy_dict = base.pop("proxy", {})
|
|
67
|
+
if proxy_dict:
|
|
68
|
+
base.update(proxy_dict)
|
|
69
|
+
return base
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from .task import TaskPayload, UserAgentPayload
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ARCaptchaTask(TaskPayload, UserAgentPayload):
|
|
9
|
+
"""
|
|
10
|
+
Represents a task for solving ARCaptcha challenges. This task does not use a proxy.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
websiteURL: Address of the main page where the captcha is located.
|
|
14
|
+
websiteKey: The siteKey value found on the page.
|
|
15
|
+
isInvisible: Set to True if the captcha is invisible.
|
|
16
|
+
"""
|
|
17
|
+
type: str = Field(default="ArCaptchaTask", frozen=True)
|
|
18
|
+
websiteURL: str = Field(..., description='Address of the main page where the captcha is located.')
|
|
19
|
+
websiteKey: str = Field(..., description='The siteKey value found on the page.')
|
|
20
|
+
isInvisible: Optional[bool] = Field(default=None, description='Set to true if the captcha is invisible.')
|
|
21
|
+
|
|
22
|
+
def to_request(self) -> dict[str, Any]:
|
|
23
|
+
return self.model_dump(exclude_none=True)
|
|
@@ -3,6 +3,7 @@ from typing import Any, Optional
|
|
|
3
3
|
from pydantic import Field, BaseModel
|
|
4
4
|
|
|
5
5
|
from .task import TaskPayload, ProxyPayload, UserAgentPayload
|
|
6
|
+
from .._deprecation import warn_deprecated
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class CastleMetadata(BaseModel):
|
|
@@ -21,6 +22,8 @@ class CastleMetadata(BaseModel):
|
|
|
21
22
|
|
|
22
23
|
class CastleTask(TaskPayload, UserAgentPayload):
|
|
23
24
|
"""
|
|
25
|
+
Deprecated: will be removed in 6.0.
|
|
26
|
+
|
|
24
27
|
Represents a task for solving Castle challenges.
|
|
25
28
|
|
|
26
29
|
Uses CustomTask type with class "Castle".
|
|
@@ -38,6 +41,10 @@ class CastleTask(TaskPayload, UserAgentPayload):
|
|
|
38
41
|
metadata: CastleMetadata = Field(..., description='Castle-specific metadata.')
|
|
39
42
|
proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
|
|
40
43
|
|
|
44
|
+
def model_post_init(self, __context: Any) -> None:
|
|
45
|
+
warn_deprecated("CastleTask is deprecated and will be removed in 6.0: "
|
|
46
|
+
"Castle is no longer in the CapMonster Cloud docs.", stacklevel=4)
|
|
47
|
+
|
|
41
48
|
def to_request(self) -> dict[str, Any]:
|
|
42
49
|
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
43
50
|
proxy_dict = base.pop("proxy", {})
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
from typing import List, Literal,
|
|
1
|
+
from typing import Any, List, Literal, Optional
|
|
2
2
|
|
|
3
|
-
from pydantic import Field
|
|
3
|
+
from pydantic import Field, model_validator
|
|
4
4
|
|
|
5
5
|
from .task import TaskPayload
|
|
6
|
+
from .._deprecation import warn_deprecated
|
|
7
|
+
from ..exceptions import CapmonsterValidationException
|
|
8
|
+
|
|
9
|
+
TASKS_WITH_ARGUMENT = ("bls_3x3", "portugal_text_find_icon")
|
|
6
10
|
|
|
7
11
|
|
|
8
12
|
class ComplexImageRecognitionTask(TaskPayload):
|
|
@@ -13,21 +17,41 @@ class ComplexImageRecognitionTask(TaskPayload):
|
|
|
13
17
|
imagesBase64: List of base64 encoded images. This is required and contains
|
|
14
18
|
raw image data in base64 format.
|
|
15
19
|
task: A string indicating one of the predefined types of recognition
|
|
16
|
-
task
|
|
17
|
-
"
|
|
20
|
+
task: "oocl_rotate_new", "oocl_rotate_double_new", "betpunch_3x3_rotate",
|
|
21
|
+
"baidu", "bls_3x3", "shein", "bills_audio", "dli", "MathSum" or
|
|
22
|
+
"portugal_text_find_icon". "bls" is deprecated: it is still sent as "bls", with a warning.
|
|
23
|
+
taskArgument: Extra task input sent as metadata "TaskArgument"; required for
|
|
24
|
+
"bls_3x3" (the number to find) and "portugal_text_find_icon" (the instruction text).
|
|
18
25
|
"""
|
|
19
26
|
type: str = Field(default="ComplexImageTask", frozen=True)
|
|
20
27
|
class_: str = Field(default="recognition", alias="class", frozen=True)
|
|
21
28
|
imagesBase64: List[str] = Field(..., description="List of base64 encoded images.")
|
|
22
|
-
task: Literal["oocl_rotate_new", "oocl_rotate_double_new", "betpunch_3x3_rotate", "
|
|
23
|
-
|
|
29
|
+
task: Literal["oocl_rotate_new", "oocl_rotate_double_new", "betpunch_3x3_rotate", "baidu", "bls_3x3", "bls",
|
|
30
|
+
"shein", "bills_audio", "dli", "MathSum", "portugal_text_find_icon"] = Field(...,
|
|
31
|
+
description="Type of task.")
|
|
32
|
+
taskArgument: Optional[str] = Field(default=None, description="Extra task input, sent as TaskArgument.")
|
|
33
|
+
|
|
34
|
+
@model_validator(mode="after")
|
|
35
|
+
def check_task(self) -> "ComplexImageRecognitionTask":
|
|
36
|
+
if self.task == "bls":
|
|
37
|
+
warn_deprecated("ComplexImageRecognitionTask(task='bls') is deprecated and will be removed in 6.0; "
|
|
38
|
+
"use task='bls_3x3' with taskArgument.", stacklevel=4)
|
|
39
|
+
elif self.task in TASKS_WITH_ARGUMENT and self.taskArgument is None:
|
|
40
|
+
raise CapmonsterValidationException(f"taskArgument is required for task '{self.task}'",
|
|
41
|
+
field="taskArgument", task="ComplexImageRecognitionTask")
|
|
42
|
+
return self
|
|
24
43
|
|
|
25
44
|
def to_request(self) -> dict[str, Any]:
|
|
26
45
|
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
27
46
|
task = base.pop("task")
|
|
47
|
+
task_argument = base.pop("taskArgument", None)
|
|
28
48
|
|
|
29
49
|
if "metadata" not in base:
|
|
30
50
|
base["metadata"] = {}
|
|
31
51
|
|
|
32
52
|
base["metadata"]["Task"] = task
|
|
53
|
+
if task_argument is not None:
|
|
54
|
+
base["metadata"]["TaskArgument"] = task_argument
|
|
55
|
+
if task == "bills_audio":
|
|
56
|
+
base["metadata"]["PayloadType"] = "Audio"
|
|
33
57
|
return base
|
|
@@ -3,6 +3,7 @@ from typing import Optional, Any
|
|
|
3
3
|
from pydantic import Field, BaseModel, model_validator
|
|
4
4
|
|
|
5
5
|
from .task import TaskPayload, UserAgentPayload, ProxyPayload
|
|
6
|
+
from .._deprecation import warn_proxy_required
|
|
6
7
|
from ..exceptions import CapmonsterValidationException
|
|
7
8
|
|
|
8
9
|
|
|
@@ -17,6 +18,7 @@ class DataDomeMetadata(BaseModel):
|
|
|
17
18
|
like: "https://geo.captcha-delivery.com/captcha/?initialCid=...".
|
|
18
19
|
datadomeCookie: Mandatory; Stores the DataDome cookies, retrievable on
|
|
19
20
|
the page using `document.cookie`.
|
|
21
|
+
datadomeVersion: Optional; DataDome script version, if the site requires it.
|
|
20
22
|
|
|
21
23
|
Raises:
|
|
22
24
|
CapmonsterValidationException: If neither `htmlPageBase64` nor `captchaUrl` is provided,
|
|
@@ -28,6 +30,8 @@ class DataDomeMetadata(BaseModel):
|
|
|
28
30
|
description="\"captchaUrl\" - link to the captcha. Usually it looks like this: \"https://geo.captcha-delivery.com/captcha/?initialCid=...\"")
|
|
29
31
|
datadomeCookie: str = Field(...,
|
|
30
32
|
description="Your cookies from datadome. You can get it on the page using document.cookie")
|
|
33
|
+
datadomeVersion: Optional[str] = Field(default=None,
|
|
34
|
+
description="DataDome script version, if the site requires it.")
|
|
31
35
|
|
|
32
36
|
@model_validator(mode="after")
|
|
33
37
|
def validate_fields(self) -> "DataDomeMetadata":
|
|
@@ -54,6 +58,10 @@ class DataDomeTask(TaskPayload, UserAgentPayload):
|
|
|
54
58
|
proxy: Optional[ProxyPayload] = Field(default=None, description="Proxy settings.")
|
|
55
59
|
metadata: DataDomeMetadata = Field(default=None, description="Additional data about the captcha.")
|
|
56
60
|
|
|
61
|
+
def model_post_init(self, __context: Any) -> None:
|
|
62
|
+
if self.proxy is None:
|
|
63
|
+
warn_proxy_required("DataDomeTask", stacklevel=4)
|
|
64
|
+
|
|
57
65
|
def to_request(self) -> dict[str, Any]:
|
|
58
66
|
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
59
67
|
proxy_dict = base.pop("proxy", {})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, BaseModel
|
|
4
|
+
|
|
5
|
+
from .task import TaskPayload, UserAgentPayload
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FengkongCloudMetadata(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
Optional metadata for FengkongCloud task.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
apiJsUrl: Link to smcp.min.js, e.g. "https://castatic.fengkongcloud.com/pr/vX.X.X/smcp.min.js".
|
|
14
|
+
"""
|
|
15
|
+
apiJsUrl: Optional[str] = Field(default=None, description='Link to smcp.min.js.')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FengkongCloudTask(TaskPayload, UserAgentPayload):
|
|
19
|
+
"""
|
|
20
|
+
Represents a task for solving FengkongCloud captcha challenges.
|
|
21
|
+
|
|
22
|
+
Uses CustomTask type with class "fengkongcloud". This task does not use a proxy.
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
websiteURL: Address of the main page where the captcha is located.
|
|
26
|
+
websiteKey: The siteKey value found on the page.
|
|
27
|
+
metadata: Optional FengkongCloud-specific metadata (apiJsUrl).
|
|
28
|
+
"""
|
|
29
|
+
type: str = Field(default="CustomTask", frozen=True)
|
|
30
|
+
class_: str = Field(default="fengkongcloud", alias="class", frozen=True)
|
|
31
|
+
websiteURL: str = Field(..., description='Address of the main page where the captcha is located.')
|
|
32
|
+
websiteKey: str = Field(..., description='The siteKey value found on the page.')
|
|
33
|
+
metadata: Optional[FengkongCloudMetadata] = Field(default=None, description='FengkongCloud-specific metadata.')
|
|
34
|
+
|
|
35
|
+
def to_request(self) -> dict[str, Any]:
|
|
36
|
+
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
37
|
+
if base.get("metadata") == {}:
|
|
38
|
+
base.pop("metadata")
|
|
39
|
+
return base
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, BaseModel
|
|
4
|
+
|
|
5
|
+
from .task import TaskPayload, ProxyPayload, UserAgentPayload
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FriendlyMetadata(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
Metadata for Friendly Captcha task.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
apiGetLib: URL of the widget JS file: for V1 the friendly-challenge widget.module.min.js,
|
|
14
|
+
for V2 the site.min.js loaded on the page.
|
|
15
|
+
"""
|
|
16
|
+
apiGetLib: str = Field(..., description='URL of the Friendly Captcha widget JS file.')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FriendlyTask(TaskPayload, UserAgentPayload):
|
|
20
|
+
"""
|
|
21
|
+
Represents a task for solving Friendly Captcha challenges.
|
|
22
|
+
|
|
23
|
+
Uses CustomTask type with class "friendly".
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
websiteURL: Full URL of the page with the captcha.
|
|
27
|
+
websiteKey: Friendly Captcha site key.
|
|
28
|
+
metadata: Friendly-specific metadata (apiGetLib).
|
|
29
|
+
proxy: Optional proxy settings.
|
|
30
|
+
"""
|
|
31
|
+
type: str = Field(default="CustomTask", frozen=True)
|
|
32
|
+
class_: str = Field(default="friendly", alias="class", frozen=True)
|
|
33
|
+
websiteURL: str = Field(..., description='Full URL of the page with the captcha.')
|
|
34
|
+
websiteKey: str = Field(..., description='Friendly Captcha site key.')
|
|
35
|
+
metadata: FriendlyMetadata = Field(..., description='Friendly-specific metadata.')
|
|
36
|
+
proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
|
|
37
|
+
|
|
38
|
+
def to_request(self) -> dict[str, Any]:
|
|
39
|
+
base = self.model_dump(exclude_none=True, by_alias=True)
|
|
40
|
+
proxy_dict = base.pop("proxy", {})
|
|
41
|
+
if proxy_dict:
|
|
42
|
+
base.update(proxy_dict)
|
|
43
|
+
return base
|