capmonster-python 3.2.0__py3-none-any.whl → 4.0.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.
Files changed (42) hide show
  1. capmonster_python/__init__.py +33 -13
  2. capmonster_python/client.py +245 -0
  3. capmonster_python/exceptions.py +60 -0
  4. capmonster_python/methods.py +32 -0
  5. capmonster_python/tasks/__init__.py +42 -0
  6. capmonster_python/tasks/basilisk.py +24 -0
  7. capmonster_python/tasks/binance.py +31 -0
  8. capmonster_python/tasks/complex_image_recaptcha.py +73 -0
  9. capmonster_python/tasks/complex_image_recognition.py +33 -0
  10. capmonster_python/tasks/datadome.py +62 -0
  11. capmonster_python/tasks/geetest.py +86 -0
  12. capmonster_python/tasks/image_to_text.py +37 -0
  13. capmonster_python/tasks/imperva.py +50 -0
  14. capmonster_python/tasks/prosopo.py +27 -0
  15. capmonster_python/tasks/recaptcha_v2.py +40 -0
  16. capmonster_python/tasks/recaptcha_v2_enterprise.py +40 -0
  17. capmonster_python/tasks/recaptcha_v3.py +30 -0
  18. capmonster_python/tasks/task.py +146 -0
  19. capmonster_python/tasks/temu.py +32 -0
  20. capmonster_python/tasks/tendi.py +30 -0
  21. capmonster_python/tasks/turnstile.py +82 -0
  22. capmonster_python-4.0.0.dist-info/METADATA +150 -0
  23. capmonster_python-4.0.0.dist-info/RECORD +26 -0
  24. {capmonster_python-3.2.0.dist-info → capmonster_python-4.0.0.dist-info}/WHEEL +1 -1
  25. capmonster_python/aws_waf.py +0 -22
  26. capmonster_python/capmonster.py +0 -253
  27. capmonster_python/compleximage.py +0 -51
  28. capmonster_python/datadome.py +0 -19
  29. capmonster_python/fun_captcha.py +0 -30
  30. capmonster_python/geetest.py +0 -26
  31. capmonster_python/hcaptcha.py +0 -36
  32. capmonster_python/image_to_text.py +0 -43
  33. capmonster_python/recaptcha_v2.py +0 -27
  34. capmonster_python/recaptcha_v2_enterprise.py +0 -30
  35. capmonster_python/recaptcha_v3.py +0 -24
  36. capmonster_python/tendi.py +0 -19
  37. capmonster_python/turnstile.py +0 -23
  38. capmonster_python/utils.py +0 -35
  39. capmonster_python-3.2.0.dist-info/METADATA +0 -120
  40. capmonster_python-3.2.0.dist-info/RECORD +0 -20
  41. {capmonster_python-3.2.0.dist-info → capmonster_python-4.0.0.dist-info/licenses}/LICENSE +0 -0
  42. {capmonster_python-3.2.0.dist-info → capmonster_python-4.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,86 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, ProxyPayload, UserAgentPayload
6
+
7
+
8
+ class GeeTestV3Task(TaskPayload, UserAgentPayload):
9
+ """
10
+ Represents a payload for solving GeeTest V3 captcha.
11
+
12
+ Attributes:
13
+ websiteURL:
14
+ Address of the page on which the captcha is being solved.
15
+ gt:
16
+ The GeeTest identifier key 'gt' corresponding to the domain.
17
+ challenge:
18
+ A dynamic key that must be fresh on each request. Reusing a non-fresh challenge
19
+ value will result in an ERROR_TOKEN_EXPIRED.
20
+ geetestApiServerSubdomain:
21
+ Optional API subdomain server for Geetest that must be different from
22
+ `api.geetest.com`.
23
+ geetestGetLib:
24
+ Optional path to the captcha script. This must be provided as a JSON string.
25
+ proxy:
26
+ Optional proxy settings to be used while solving the captcha.
27
+ """
28
+ type: str = Field(default="GeeTestTask", frozen=True)
29
+ websiteURL: str = Field(..., description="Address of the page on which the captcha is solved.")
30
+ gt: str = Field(..., description="The GeeTest identifier key gt for the domain.")
31
+ challenge: str = Field(..., description=(
32
+ "A dynamic key. Must be fresh on each request. If the captcha is loaded on the page, "
33
+ "then the challenge value is no longer valid and you will get ERROR_TOKEN_EXPIRED."
34
+ ))
35
+ geetestApiServerSubdomain: Optional[str] = Field(
36
+ default=None, description="Geetest API subdomain server (must differ from api.geetest.com)"
37
+ )
38
+ geetestGetLib: Optional[str] = Field(
39
+ default=None, description="Path to captcha script. Must be passed as JSON string."
40
+ )
41
+ proxy: Optional[ProxyPayload] = Field(default=None, description="Proxy settings.")
42
+
43
+ def to_request(self) -> dict[str, Any]:
44
+ base = self.model_dump(exclude_none=True)
45
+ proxy_dict = base.pop("proxy", {})
46
+ if proxy_dict:
47
+ base.update(proxy_dict)
48
+ return base
49
+
50
+
51
+ class GeeTestV4Task(TaskPayload, UserAgentPayload):
52
+ """
53
+ Represents a GeeTest V4 task payload.
54
+
55
+ Attributes:
56
+ type: Indicates the type of the task, defaulted and frozen as "GeeTestTask".
57
+ websiteURL: Address of the page on which the captcha is solved.
58
+ gt: The GeeTest identifier key gt for the domain.
59
+ version: Version of the GeeTest task, defaulted and frozen as 4.
60
+ initParameters: Extra parameters for v4, used with 'riskType' or challenge details.
61
+ geetestApiServerSubdomain: Geetest API subdomain server (must differ from api.geetest.com).
62
+ geetestGetLib: Path to a captcha script. Must be passed as a JSON string.
63
+ proxy: Proxy settings to be used for the task.
64
+ """
65
+ type: str = Field(default="GeeTestTask", frozen=True)
66
+ websiteURL: str = Field(..., description="Address of the page on which the captcha is solved.")
67
+ gt: str = Field(..., description="The GeeTest identifier key gt for the domain.")
68
+ version: int = Field(default=4, frozen=True)
69
+ initParameters: Optional[object] = Field(
70
+ default=None,
71
+ description="Extra parameters for v4, used with 'riskType' or challenge details."
72
+ )
73
+ geetestApiServerSubdomain: Optional[str] = Field(
74
+ default=None, description="Geetest API subdomain server (must differ from api.geetest.com)"
75
+ )
76
+ geetestGetLib: Optional[str] = Field(
77
+ default=None, description="Path to captcha script. Must be passed as JSON string."
78
+ )
79
+ proxy: Optional[ProxyPayload] = Field(default=None, description="Proxy settings.")
80
+
81
+ def to_request(self) -> dict[str, Any]:
82
+ base = self.model_dump(exclude_none=True)
83
+ proxy_dict = base.pop("proxy", {})
84
+ if proxy_dict:
85
+ base.update(proxy_dict)
86
+ return base
@@ -0,0 +1,37 @@
1
+ from typing import Optional, Literal, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload
6
+
7
+
8
+ class ImageToTextTask(TaskPayload):
9
+ """
10
+ Represents a task for solving image-based captcha using certain recognition parameters.
11
+
12
+ Attributes:
13
+ body (str): File body encoded in base64. Ensure it is passed without any line breaks.
14
+ capMonsterModule (Optional[str]): The name of the recognition module (e.g., "yandex").
15
+ recognizingThreshold (Optional[int]): The threshold for captcha recognition confidence
16
+ with a range of 0 to 100. Ensures that you are charged only if recognition confidence
17
+ meets or exceeds this value.
18
+ case (Optional[bool]): Indicates whether the captcha is case-sensitive.
19
+ numeric (Optional[Literal[0, 1]]): Set to 1 if the captcha consists only of numbers.
20
+ math (Optional[bool]): Set to true if the captcha involves solving a mathematical operation.
21
+ """
22
+ type: str = Field(default="ImageToTextTask", frozen=True)
23
+ body: str = Field(..., description="File body encoded in base64*. Make sure to pass it without line breaks.")
24
+ capMonsterModule: Optional[str] = Field(default=None,
25
+ description="The name of recognizing module, for example, “yandex“.")
26
+ recognizingThreshold: Optional[int] = Field(default=None,
27
+ description="Captcha recognition threshold with a possible value from "
28
+ "0 to 100. For example, if recognizingThreshold was set to "
29
+ "90 and the task was solved with a confidence of 80, "
30
+ "you won't be charged.",
31
+ ge=0, le=100)
32
+ case: Optional[bool] = Field(default=None, description="Set to true if captcha is case sensitive.")
33
+ numeric: Optional[Literal[0, 1]] = Field(default=None, description="Set to 1 if captcha contains numbers only.")
34
+ math: Optional[bool] = Field(default=None, description="Set to true if captcha requires a mathematical operation.")
35
+
36
+ def to_request(self) -> dict[str, Any]:
37
+ return self.model_dump(exclude_none=True)
@@ -0,0 +1,50 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field, BaseModel
4
+
5
+ from .task import TaskPayload, UserAgentPayload
6
+
7
+
8
+ class ImpervaTaskMetadata(BaseModel):
9
+ """
10
+ Represents metadata related to an Imperva task.
11
+
12
+ Attributes:
13
+ incapsulaScriptUrl: Name of the Incapsula JS file.
14
+ incapsulaCookie: Your cookies from Incapsula. They can be obtained on the
15
+ page using document.cookie.
16
+ reese84UrlEndpoint: Optional. The name of the endpoint where the reese84
17
+ fingerprint is sent, found among the network requests and typically
18
+ ending with "?d=site.com".
19
+ """
20
+ incapsulaScriptUrl: str = Field(..., description="Name of the Incapsula JS file.")
21
+ incapsulaCookie: str = Field(...,
22
+ description="Your cookies from Incapsula. They can be obtained on the page using document.cookie")
23
+ reese84UrlEndpoint: Optional[str] = Field(default=None, description="The name of the endpoint where the reese84 "
24
+ "fingerprint is sent can be found among the "
25
+ "requests and ends with ?d=site.com")
26
+
27
+
28
+ class ImpervaTask(TaskPayload, UserAgentPayload):
29
+ """
30
+ Represents a task for handling and solving an Imperva-based challenge.
31
+
32
+ Attributes:
33
+ type (str): The identifier for the type of task. This attribute is
34
+ frozen and defaults to "CustomTask".
35
+
36
+ class_ (str): The identifier for the class of the task. This attribute is
37
+ frozen, defaults to "Imperva", and is aliased to "class" for external usage.
38
+
39
+ websiteURL (str): The URL of the website targeted for solving the challenge.
40
+
41
+ metadata (ImpervaTaskMetadata): Encapsulated metadata specific to the
42
+ Imperva challenge, such as the website key.
43
+ """
44
+ type: str = Field(default="CustomTask", frozen=True)
45
+ class_: str = Field(default="Imperva", alias="class", frozen=True)
46
+ websiteURL: str = Field(..., description="URL of the website to be solved.")
47
+ metadata: ImpervaTaskMetadata = Field(..., description="Website key.")
48
+
49
+ def to_request(self) -> dict[str, Any]:
50
+ return self.model_dump(exclude_none=True, by_alias=True)
@@ -0,0 +1,27 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, ProxyPayload
6
+
7
+
8
+ class ProsopoTask(TaskPayload):
9
+ """
10
+ Represents a Prosopo CAPTCHA solving task.
11
+
12
+ Attributes:
13
+ websiteURL: The full URL of the CAPTCHA page that needs to be solved.
14
+ websiteKey: The site key parameter value obtained from the CAPTCHA page.
15
+ proxy: Optional proxy settings to be used in sending the task request.
16
+ """
17
+ type: str = Field(default="ProsopoTask", frozen=True)
18
+ websiteURL: str = Field(..., description="The full URL of the CAPTCHA page.")
19
+ websiteKey: str = Field(..., description="The value of the siteKey parameter found on the page.")
20
+ proxy: Optional[ProxyPayload] = Field(default=None, description="Proxy settings.")
21
+
22
+ def to_request(self) -> dict[str, Any]:
23
+ base = self.model_dump(exclude_none=True)
24
+ proxy_dict = base.pop("proxy", {})
25
+ if proxy_dict:
26
+ base.update(proxy_dict)
27
+ return base
@@ -0,0 +1,40 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, ProxyPayload, UserAgentPayload
6
+
7
+
8
+ class RecaptchaV2Task(TaskPayload, UserAgentPayload):
9
+ """
10
+ Represents a payload structure for solving reCAPTCHA v2 challenges.
11
+
12
+ Attributes:
13
+ type: The constant string value identifying the task type as "RecaptchaV2Task".
14
+ websiteURL: The URL of the webpage containing the reCAPTCHA challenge.
15
+ websiteKey: The site key associated with the reCAPTCHA on the webpage.
16
+ recaptchaDataSValue: A one-time token specific to certain custom
17
+ implementations of reCAPTCHA v2. If applicable, this parameter needs
18
+ to be retrieved for each challenge-solving attempt.
19
+ isInvisible: When set to True, specifies that the challenge
20
+ being solved is an invisible reCAPTCHA.
21
+ proxy: Proxy settings to route the request through a specified
22
+ proxy server.
23
+ """
24
+ type: str = Field(default="RecaptchaV2Task", frozen=True)
25
+ websiteURL: str = Field(..., description='Address of a webpage with captcha.')
26
+ websiteKey: str = Field(..., description='reCAPTCHA website key.')
27
+ recaptchaDataSValue: Optional[str] = Field(default=None,
28
+ description='Some custom implementations may contain additional "data-s" '
29
+ 'parameter in ReCaptcha2 div, which is in fact a one-time token '
30
+ 'and must be grabbed every time you want to solve a reCAPTCHA v2.')
31
+ isInvisible: Optional[bool] = Field(default=None,
32
+ description='Set to true if you want to solve invisible reCAPTCHA.')
33
+ proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
34
+
35
+ def to_request(self) -> dict[str, Any]:
36
+ base = self.model_dump(exclude_none=True)
37
+ proxy_dict = base.pop("proxy", {})
38
+ if proxy_dict:
39
+ base.update(proxy_dict)
40
+ return base
@@ -0,0 +1,40 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, ProxyPayload, UserAgentPayload
6
+
7
+
8
+ class RecaptchaV2EnterpriseTask(TaskPayload, UserAgentPayload):
9
+ """
10
+ Represents a task payload for solving Google reCAPTCHA V2 Enterprise challenges.
11
+
12
+ Attributes:
13
+ websiteURL: The address of a webpage with Google reCAPTCHA Enterprise.
14
+ websiteKey: The reCAPTCHA website key.
15
+ enterprisePayload: An optional parameter containing additional values passed
16
+ to the 'grecaptcha.enterprise.render' method along with the sitekey.
17
+ apiDomain: An optional domain address from which to load reCAPTCHA Enterprise.
18
+ This parameter should only be set if explicitly needed.
19
+ cookies: Optional cookies to be sent with the request.
20
+ proxy: Optional proxy settings for handling the task.
21
+ """
22
+ type: str = Field(default="RecaptchaV2EnterpriseTask", frozen=True)
23
+ websiteURL: str = Field(..., description='Address of a webpage with Google reCAPTCHA Enterprise.')
24
+ websiteKey: str = Field(..., description='reCAPTCHA website key.')
25
+ enterprisePayload: Optional[str] = Field(default=None,
26
+ description='Some implementations of the reCAPTCHA Enterprise widget '
27
+ 'may contain additional parameters that are passed to the '
28
+ '“grecaptcha.enterprise.render” method along with the sitekey.')
29
+ apiDomain: Optional[str] = Field(default=None,
30
+ description='Domain address from which to load reCAPTCHA Enterprise. '
31
+ 'Don\'t use a parameter if you don\'t know why it\'s needed.')
32
+ cookies: Optional[str] = Field(default=None, description='Cookies to be sent with the request.')
33
+ proxy: Optional[ProxyPayload] = Field(default=None, description='Proxy settings.')
34
+
35
+ def to_request(self) -> dict[str, Any]:
36
+ base = self.model_dump(exclude_none=True)
37
+ proxy_dict = base.pop("proxy", {})
38
+ if proxy_dict:
39
+ base.update(proxy_dict)
40
+ return base
@@ -0,0 +1,30 @@
1
+ from typing import Any, Optional
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload
6
+
7
+
8
+ class RecaptchaV3Task(TaskPayload):
9
+ """
10
+ Represents a task for solving Google reCAPTCHA v3 without using a proxy.
11
+
12
+ Attributes:
13
+ websiteURL: Address of the webpage that contains the reCAPTCHA to be solved.
14
+ websiteKey: The specific site key corresponding to the reCAPTCHA on the target website.
15
+ minScore: Defines the minimum acceptable score required for the captcha
16
+ result, ranging between 0.1 and 0.9. Setting this helps filter the quality of
17
+ the solution response.
18
+ pageAction: Specifies the widget action value, typically indicating what
19
+ the user action represents on the page. This value is set by the website owner.
20
+ """
21
+ type: str = Field(default="RecaptchaV3TaskProxyless", frozen=True)
22
+ websiteURL: str = Field(..., description='Address of a webpage with captcha.')
23
+ websiteKey: str = Field(..., description='reCAPTCHA website key.')
24
+ minScore: Optional[float] = Field(default=None, description='Minimum score of a captcha.', ge=0.1, le=0.9)
25
+ pageAction: Optional[str] = Field(default=None,
26
+ description='Widget action value. Website owner defines what user is doing on '
27
+ 'the page through this parameter. Default value: verify')
28
+
29
+ def to_request(self) -> dict[str, Any]:
30
+ return self.model_dump(exclude_none=True)
@@ -0,0 +1,146 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional, Dict, Any, Literal
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+
7
+ class TaskPayload(BaseModel, ABC):
8
+ """
9
+ Represents a base payload structure for a specific task type.
10
+
11
+ This class serves as an abstract base model for defining the structure
12
+ and behavior of task payloads. The `type` attribute specifies the type
13
+ of task, and subclasses are required to implement the `to_request` method,
14
+ which converts the instance into a format compatible with API requests.
15
+
16
+ Attributes:
17
+ type (str): The task type identifier sent to the Capmonster API, generally constant.
18
+ """
19
+ type: str = Field(..., description="Task type")
20
+
21
+ @abstractmethod
22
+ def to_request(self) -> Dict[str, Any]:
23
+ """
24
+ Converts the instance's model data into a request-compatible dictionary.
25
+
26
+ Returns:
27
+ dict[str, Any]: A dictionary representation of the model data, formatted
28
+ for request purposes.
29
+ """
30
+ pass
31
+
32
+
33
+ class ProxyPayload(BaseModel):
34
+ """
35
+ Represents proxy information and validation for usage.
36
+
37
+ This class defines the structure and validation logic for a proxy configuration.
38
+ It includes fields for the proxy type, address, port, and optional authentication
39
+ credentials. It ensures that mandatory fields such as proxyAddress and proxyPort
40
+ are provided if proxyType is specified.
41
+
42
+ Attributes:
43
+ proxyType (Literal["http", "https", "socks4", "socks5"]): The type of proxy.
44
+ proxyAddress (str): The IP address or hostname of the proxy server.
45
+ proxyPort (int): The port number of the proxy server.
46
+ proxyLogin (Optional[str]): The username for proxy authentication, if required.
47
+ proxyPassword (Optional[str]): The password for proxy authentication, if required.
48
+
49
+ Example:
50
+ ```python
51
+ client = CapmonsterClient("YOUR_API_KEY")
52
+ task_id = client.create_task(
53
+ RecaptchaV2Task(
54
+ websiteURL="https://www.google.com/recaptcha/api2/demo",
55
+ websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
56
+ proxy=ProxyPayload(
57
+ proxyType="https",
58
+ proxyAddress="192.168.1.1",
59
+ proxyPort=8080,
60
+ proxyLogin="<USERNAME>",
61
+ proxyPassword="<PASSWORD>")
62
+ )
63
+ )
64
+ ```
65
+ """
66
+ proxyType: Literal["http", "https", "socks4", "socks5"] = Field(
67
+ ..., description="Type of the proxy (http, https, socks4, socks5)"
68
+ )
69
+ proxyAddress: str = Field(
70
+ ..., title="Proxy Address",
71
+ description="IPv4/IPv6 proxy IP address. Hostnames, transparent and local proxies are not allowed."
72
+ )
73
+ proxyPort: int = Field(
74
+ ..., title="Proxy Port",
75
+ description="Port of the proxy."
76
+ )
77
+ proxyLogin: Optional[str] = Field(
78
+ default=None, description="Username for proxy authentication."
79
+ )
80
+ proxyPassword: Optional[str] = Field(
81
+ default=None, description="Password for proxy authentication."
82
+ )
83
+
84
+
85
+ class UserAgentPayload(BaseModel, ABC):
86
+ """
87
+ Represents a payload containing a browser User-Agent string.
88
+
89
+ This class is designed as a data model for handling the browser User-Agent
90
+ string, typically used to recognize and handle captcha services effectively.
91
+ It extends from BaseModel to provide data validation and supports optional
92
+ specification of the User-Agent string.
93
+
94
+ Attributes:
95
+ userAgent: Field containing the browser User-Agent string. When
96
+ provided, it helps to identify specific browser instances for captcha
97
+ recognition.
98
+ """
99
+ userAgent: Optional[str] = Field(
100
+ default=None,
101
+ description="Browser User-Agent string used to recognize captcha."
102
+ )
103
+
104
+
105
+ class VanillaTaskPayload(TaskPayload, UserAgentPayload):
106
+ """
107
+ Base class for forward-compatible CAPTCHA task payloads.
108
+
109
+ This class is designed to support rapid user adaptation to new or evolving Capmonster task formats.
110
+ It enables developers to define payloads for newly introduced task types, or to extend existing tasks
111
+ with additional fields without waiting for an official library update.
112
+
113
+ Intended for:
114
+ - Users who need to work with task types not yet implemented in the SDK.
115
+ - Scenarios where Capmonster API introduces new fields to existing tasks.
116
+
117
+ Attributes:
118
+ type (str): The task type identifier sent to the Capmonster API. Must be overridden in subclasses.
119
+
120
+ Notes:
121
+ - Can be subclassed to define completely custom tasks.
122
+ - Provides a stable structure while allowing dynamic extension.
123
+
124
+ Example:
125
+ Use this as a base to quickly integrate a new task format:
126
+
127
+ ```python
128
+ class CustomCaptchaTask(VanillaTaskPayload):
129
+ type: str = "NewCustomTask"
130
+ custom_field: str
131
+ ```
132
+ """
133
+
134
+ type: str = Field(..., description="Task type string, e.g. 'CustomTask'")
135
+ proxy: Optional[ProxyPayload] = Field(default=None, description="Proxy settings (optional)")
136
+
137
+ model_config = {
138
+ "extra": "allow"
139
+ }
140
+
141
+ def to_request(self) -> dict[str, Any]:
142
+ base = self.model_dump(exclude_none=True)
143
+ proxy_dict = base.pop("proxy", {})
144
+ if proxy_dict:
145
+ base.update(proxy_dict)
146
+ return base
@@ -0,0 +1,32 @@
1
+ from typing import Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, UserAgentPayload
6
+
7
+
8
+ class TemuTask(TaskPayload, UserAgentPayload):
9
+ """
10
+ Represents a Temu task for CAPTCHA challenge handling.
11
+
12
+ Attributes:
13
+ class_ (str): The class name for the task, aliased as "class" for JSON
14
+ compatibility. This is always set to "Temu" and is immutable.
15
+ websiteURL (str): The full URL of the webpage where the CAPTCHA is loaded.
16
+ cookie (str): Cookies obtained from the webpage where the CAPTCHA is
17
+ loaded. These cookies are typically required for CAPTCHA validation.
18
+ """
19
+ type: str = Field(default="CustomTask", frozen=True)
20
+ class_: str = Field(default="Temu", alias="class", frozen=True)
21
+ websiteURL: str = Field(..., description="The full URL of the page where the CAPTCHA is loaded.")
22
+ cookie: str = Field(..., description="Cookies obtained from the page where the CAPTCHA is loaded.")
23
+
24
+ def to_request(self) -> dict[str, Any]:
25
+ base = self.model_dump(exclude_none=True, by_alias=True)
26
+ cookie = base.pop("cookie")
27
+
28
+ if "metadata" not in base:
29
+ base["metadata"] = {}
30
+
31
+ base["metadata"]["cookie"] = cookie
32
+ return base
@@ -0,0 +1,30 @@
1
+ from typing import Optional, Any
2
+
3
+ from pydantic import Field
4
+
5
+ from .task import TaskPayload, UserAgentPayload, ProxyPayload
6
+
7
+
8
+ class TenDITask(TaskPayload, UserAgentPayload):
9
+ """
10
+ Represents a task configuration for solving a captcha using the TenDI service.
11
+
12
+ Attributes:
13
+ class_: Represents the class name of the task. Default is "TenDI".
14
+ websiteURL: Address of the page on which the captcha is solved.
15
+ websiteKey: A unique identifier (captchaAppId) specific to the site.
16
+ proxy: Optional. Proxy settings for the task, if applicable.
17
+ """
18
+ type: str = Field(default="CustomTask", frozen=True)
19
+ class_: str = Field(default="TenDI", alias="class", frozen=True)
20
+ websiteURL: str = Field(..., description="Address of the page on which the captcha is solved.")
21
+ websiteKey: str = Field(..., description="captchaAppId. For example websiteKey: 189123456 - is a "
22
+ "unique parameter for your site.")
23
+ proxy: Optional[ProxyPayload] = Field(..., description="Proxy settings.")
24
+
25
+ def to_request(self) -> dict[str, Any]:
26
+ base = self.model_dump(exclude_none=True, by_alias=True)
27
+ proxy_dict = base.pop("proxy", {})
28
+ if proxy_dict:
29
+ base.update(proxy_dict)
30
+ return base
@@ -0,0 +1,82 @@
1
+ from typing import Optional, Dict, Any, Literal
2
+
3
+ from pydantic import Field, model_validator
4
+
5
+ from .task import TaskPayload, ProxyPayload
6
+ from ..exceptions import CapmonsterValidationException
7
+
8
+
9
+ class TurnstileTask(TaskPayload):
10
+ """
11
+ Represents a TurnstileTask used for solving captcha.
12
+
13
+ Attributes:
14
+ websiteURL: A required string containing the page address where the captcha
15
+ is solved.
16
+ websiteKey: A required string for the Turnstile key.
17
+ pageAction: An optional string representing the action field that can be
18
+ found in the callback function to load the captcha.
19
+ data: An optional string containing the value of the data field, which can
20
+ be obtained from the cData parameter.
21
+ """
22
+ type: str = Field(default="TurnstileTaskProxyless", frozen=True)
23
+ websiteURL: str = Field(..., description='The page address, where the captcha is solved')
24
+ websiteKey: str = Field(..., description='Turnstile key.')
25
+ pageAction: Optional[str] = Field(default=None, description='The action field that can be found in the callback '
26
+ 'function to load the captcha')
27
+ data: Optional[str] = Field(default=None,
28
+ description='The value of the data field can be taken from the cData parameter.')
29
+
30
+ def to_request(self) -> Dict[str, Any]:
31
+ return self.model_dump(exclude_none=True)
32
+
33
+
34
+ class TurnstileCloudFlareTask(TurnstileTask):
35
+ """
36
+ Represents a Turnstile task for Cloudflare challenges.
37
+
38
+ Attributes:
39
+ cloudflareTaskType: Specifies the Cloudflare challenge type. Expected
40
+ values are "token" or "cf_clearance".
41
+ userAgent: Browser User-Agent string, must originate from a Windows OS.
42
+ apiJsUrl: Optional captcha script URL, applicable only for "token" type tasks.
43
+ htmlPageBase64: Base64-encoded HTML page content, required for tasks
44
+ with "cf_clearance" type.
45
+ proxy: Optional proxy settings; mandatory for the "cf_clearance" type and
46
+ omitted for the "token" type.
47
+
48
+ Raises:
49
+ CapmonsterValidationException: When field requirements specific to the `cloudflareTaskType`
50
+ are not satisfied.
51
+ """
52
+ type: str = Field(default="TurnstileTask")
53
+ cloudflareTaskType: Literal["token", "cf_clearance"] = Field(default="token",
54
+ description="Type of Cloudflare challenge")
55
+ userAgent: str = Field(..., description="Browser User-Agent string (must be from Windows OS)")
56
+ apiJsUrl: Optional[str] = Field(default=None, description="Captcha script URL (only for token-based tasks)")
57
+ htmlPageBase64: Optional[str] = Field(default=None,
58
+ description="Base64-encoded HTML page content, required for cf_clearance type")
59
+ proxy: Optional[ProxyPayload] = Field(
60
+ default=None, description="Proxy settings (required if type is cf_clearance)"
61
+ )
62
+
63
+ @model_validator(mode="after")
64
+ def check_fields_match_type(self) -> "TurnstileCloudFlareTask":
65
+ if self.cloudflareTaskType == "token":
66
+ if not self.apiJsUrl:
67
+ raise CapmonsterValidationException("apiJsUrl is required for cloudflareTaskType='token'")
68
+ if self.proxy is not None:
69
+ raise CapmonsterValidationException("proxy must be omitted for cloudflareTaskType='token'")
70
+ elif self.cloudflareTaskType == "cf_clearance":
71
+ if not self.htmlPageBase64:
72
+ raise CapmonsterValidationException("htmlPageBase64 is required for cloudflareTaskType='cf_clearance'")
73
+ if self.proxy is None:
74
+ raise CapmonsterValidationException("proxy is required for cloudflareTaskType='cf_clearance'")
75
+ return self
76
+
77
+ def to_request(self) -> dict[str, Any]:
78
+ base = self.model_dump(exclude_none=True)
79
+ proxy_dict = base.pop("proxy", {})
80
+ if proxy_dict:
81
+ base.update(proxy_dict)
82
+ return base