capmonster-python 2.5.0__py3-none-any.whl → 2.6.1__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 +1 -0
- capmonster_python/capmonster.py +57 -6
- capmonster_python/compleximage.py +6 -5
- capmonster_python/datadome.py +19 -0
- capmonster_python/recaptcha_v2_enterprise.py +3 -2
- capmonster_python/utils.py +3 -1
- {capmonster_python-2.5.0.dist-info → capmonster_python-2.6.1.dist-info}/METADATA +8 -4
- capmonster_python-2.6.1.dist-info/RECORD +18 -0
- capmonster_python-2.5.0.dist-info/RECORD +0 -17
- {capmonster_python-2.5.0.dist-info → capmonster_python-2.6.1.dist-info}/LICENSE +0 -0
- {capmonster_python-2.5.0.dist-info → capmonster_python-2.6.1.dist-info}/WHEEL +0 -0
- {capmonster_python-2.5.0.dist-info → capmonster_python-2.6.1.dist-info}/top_level.txt +0 -0
capmonster_python/__init__.py
CHANGED
capmonster_python/capmonster.py
CHANGED
|
@@ -5,6 +5,7 @@ from .utils import *
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class Capmonster:
|
|
8
|
+
"""A class that interacts with the Capmonster API."""
|
|
8
9
|
__SOFT_ID = 30
|
|
9
10
|
_HOST_URL = "https://api.capmonster.cloud"
|
|
10
11
|
_CREATE_TASK_URL = "/createTask"
|
|
@@ -16,11 +17,20 @@ class Capmonster:
|
|
|
16
17
|
def __init__(self, client_key):
|
|
17
18
|
self._client_key = client_key
|
|
18
19
|
|
|
19
|
-
def get_balance(self):
|
|
20
|
+
def get_balance(self) -> float:
|
|
21
|
+
"""
|
|
22
|
+
Retrieves the balance of the client.
|
|
23
|
+
|
|
24
|
+
:return: The balance of the client as a float.
|
|
25
|
+
"""
|
|
20
26
|
data = {"clientKey": self._client_key}
|
|
21
27
|
return self._make_request("getBalance", data).get("balance")
|
|
22
28
|
|
|
23
29
|
def get_task_result(self, task_id: int):
|
|
30
|
+
"""
|
|
31
|
+
:param task_id: The ID of the task for which the result is requested.
|
|
32
|
+
:return: The result of the task if it is ready, otherwise False.
|
|
33
|
+
"""
|
|
24
34
|
data = {
|
|
25
35
|
"clientKey": self._client_key,
|
|
26
36
|
"taskId": task_id
|
|
@@ -55,7 +65,15 @@ class Capmonster:
|
|
|
55
65
|
61, "ERROR_MAXIMUM_TIME_EXCEED", "Maximum time is exceed.")
|
|
56
66
|
|
|
57
67
|
def report_incorrect_captcha(self, captcha_type: str, task_id: int) -> bool:
|
|
58
|
-
|
|
68
|
+
"""
|
|
69
|
+
Reports an incorrect captcha.
|
|
70
|
+
|
|
71
|
+
:param captcha_type: The type of captcha ("image" or "token").
|
|
72
|
+
:param task_id: The ID of the task.
|
|
73
|
+
:return: True if the captcha is successfully reported, False otherwise.
|
|
74
|
+
:raises CapmonsterException: If the captcha type is invalid.
|
|
75
|
+
"""
|
|
76
|
+
if captcha_type != "image" or "token":
|
|
59
77
|
raise CapmonsterException(
|
|
60
78
|
1, "ERROR_INCORRECT_CAPTCHA_TYPE", "Valid captcha_type parameters are only 'image' or 'token'.")
|
|
61
79
|
try:
|
|
@@ -71,7 +89,7 @@ class Capmonster:
|
|
|
71
89
|
"clientKey": self._client_key,
|
|
72
90
|
"taskId": task_id
|
|
73
91
|
}
|
|
74
|
-
if captcha_type
|
|
92
|
+
if captcha_type == "image":
|
|
75
93
|
response = self._make_request("reportIncorrectImageCaptcha", data)
|
|
76
94
|
else:
|
|
77
95
|
response = self._make_request("reportIncorrectTokenCaptcha", data)
|
|
@@ -111,13 +129,13 @@ class Capmonster:
|
|
|
111
129
|
if cookies is None:
|
|
112
130
|
return data
|
|
113
131
|
str_cookies = ""
|
|
114
|
-
if type(cookies)
|
|
132
|
+
if type(cookies) is dict:
|
|
115
133
|
for key, value in cookies.items():
|
|
116
134
|
if value == list(cookies.items())[-1][1]:
|
|
117
135
|
str_cookies += "{}={}".format(key, value)
|
|
118
136
|
else:
|
|
119
137
|
str_cookies += "{}={};".format(key, value)
|
|
120
|
-
elif type(cookies)
|
|
138
|
+
elif type(cookies) is list:
|
|
121
139
|
for i in cookies:
|
|
122
140
|
if not len(cookies) % 2 == 0:
|
|
123
141
|
raise AttributeError(
|
|
@@ -128,7 +146,7 @@ class Capmonster:
|
|
|
128
146
|
str_cookies += "{}".format(i)
|
|
129
147
|
elif cookies.index(i) % 2 == 1:
|
|
130
148
|
str_cookies += "{};".format(i)
|
|
131
|
-
elif type(cookies)
|
|
149
|
+
elif type(cookies) is str:
|
|
132
150
|
data["task"]["cookies"] = cookies
|
|
133
151
|
return data
|
|
134
152
|
data["task"]["cookies"] = str_cookies
|
|
@@ -146,6 +164,16 @@ class Proxy(Capmonster):
|
|
|
146
164
|
|
|
147
165
|
def set_proxy(self, proxy_type: str, proxy_address: str, proxy_port: int,
|
|
148
166
|
proxy_login: str = None, proxy_password: str = None):
|
|
167
|
+
"""
|
|
168
|
+
Sets the proxy settings for the client.
|
|
169
|
+
|
|
170
|
+
:param proxy_type: The type of the proxy. (e.g. "HTTP", "SOCKS5")
|
|
171
|
+
:param proxy_address: The address of the proxy server.
|
|
172
|
+
:param proxy_port: The port number of the proxy server.
|
|
173
|
+
:param proxy_login: (optional) The login username for proxy authentication.
|
|
174
|
+
:param proxy_password: (optional) The login password for proxy authentication.
|
|
175
|
+
:return: None
|
|
176
|
+
"""
|
|
149
177
|
self._proxy_type = proxy_type
|
|
150
178
|
self._proxy_address = proxy_address
|
|
151
179
|
self._proxy_port = proxy_port
|
|
@@ -153,6 +181,11 @@ class Proxy(Capmonster):
|
|
|
153
181
|
self._proxy_password = proxy_password
|
|
154
182
|
|
|
155
183
|
def disable_proxy(self):
|
|
184
|
+
"""
|
|
185
|
+
Disables the proxy settings.
|
|
186
|
+
|
|
187
|
+
:return: None
|
|
188
|
+
"""
|
|
156
189
|
self._proxy_type = None
|
|
157
190
|
self._proxy_address = None
|
|
158
191
|
self._proxy_port = None
|
|
@@ -184,9 +217,20 @@ class UserAgent(Capmonster):
|
|
|
184
217
|
self._fallback = False
|
|
185
218
|
|
|
186
219
|
def set_user_agent(self, user_agent: str):
|
|
220
|
+
"""
|
|
221
|
+
Set the user agent for the instance.
|
|
222
|
+
|
|
223
|
+
:param user_agent: The user agent string to set.
|
|
224
|
+
:return: None
|
|
225
|
+
"""
|
|
187
226
|
self._user_agent = user_agent
|
|
188
227
|
|
|
189
228
|
def reset_user_agent(self):
|
|
229
|
+
"""
|
|
230
|
+
Reset the user agent to None.
|
|
231
|
+
|
|
232
|
+
:return:
|
|
233
|
+
"""
|
|
190
234
|
self._user_agent = None
|
|
191
235
|
|
|
192
236
|
def _add_user_agent(self, data):
|
|
@@ -197,4 +241,11 @@ class UserAgent(Capmonster):
|
|
|
197
241
|
return data, False
|
|
198
242
|
|
|
199
243
|
def set_fallback_to_actual_user_agent(self, fallback: bool):
|
|
244
|
+
"""
|
|
245
|
+
Set the fallback value for the actual user agent.
|
|
246
|
+
|
|
247
|
+
:param fallback: A boolean value indicating whether to enable or disable the fallback.
|
|
248
|
+
:type fallback: bool
|
|
249
|
+
:return: None
|
|
250
|
+
"""
|
|
200
251
|
self._fallback = fallback
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
from .capmonster import UserAgent
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
class ComplexImageTask(UserAgent):
|
|
4
5
|
def __init__(self, client_key):
|
|
5
6
|
super(ComplexImageTask, self).__init__(client_key)
|
|
6
|
-
|
|
7
|
+
|
|
7
8
|
def create_task(self, _class: str, grid: str = None,
|
|
8
9
|
task_definition: str = None,
|
|
9
10
|
image_urls: list = None,
|
|
10
11
|
images_base64: list = None,
|
|
11
12
|
task: str = None,
|
|
12
13
|
websiteUrl: str = None):
|
|
13
|
-
if _class
|
|
14
|
+
if _class != "recaptcha" or _class != "hcaptcha":
|
|
14
15
|
raise ValueError("Currently only recaptcha or hcaptcha is supported as _class value.")
|
|
15
16
|
data = {
|
|
16
17
|
"clientKey": self._client_key,
|
|
@@ -26,7 +27,7 @@ class ComplexImageTask(UserAgent):
|
|
|
26
27
|
data["task"]["imagesBase64"] = images_base64
|
|
27
28
|
else:
|
|
28
29
|
raise ValueError("image_urls or images_base64 must be sent")
|
|
29
|
-
if _class
|
|
30
|
+
if _class == "recaptcha":
|
|
30
31
|
if grid is None:
|
|
31
32
|
raise ValueError("Grid parameter must sent with recaptcha")
|
|
32
33
|
else:
|
|
@@ -37,7 +38,7 @@ class ComplexImageTask(UserAgent):
|
|
|
37
38
|
data["task"]["metadata"]["TaskDefinition"] = task_definition
|
|
38
39
|
else:
|
|
39
40
|
raise ValueError("task_definition or task parameter must be sent")
|
|
40
|
-
elif _class
|
|
41
|
+
elif _class == "hcaptcha":
|
|
41
42
|
if task is not None:
|
|
42
43
|
data["task"]["metadata"]["Task"] = task
|
|
43
44
|
else:
|
|
@@ -45,4 +46,4 @@ class ComplexImageTask(UserAgent):
|
|
|
45
46
|
if websiteUrl is not None:
|
|
46
47
|
data["task"]["websiteUrl"] = websiteUrl
|
|
47
48
|
data, is_user_agent = self._add_user_agent(data)
|
|
48
|
-
return self._make_request("createTask", data).get("taskId")
|
|
49
|
+
return self._make_request("createTask", data).get("taskId")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .capmonster import UserAgent
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DataDomeTask(UserAgent):
|
|
5
|
+
def __init__(self, client_key):
|
|
6
|
+
super(DataDomeTask, self).__init__(client_key)
|
|
7
|
+
|
|
8
|
+
def create_task(self, website_url: str, metadata: object):
|
|
9
|
+
data = {
|
|
10
|
+
"client_key": self._client_key,
|
|
11
|
+
"task": {
|
|
12
|
+
"type": "CustomTask",
|
|
13
|
+
"class": "DataDome",
|
|
14
|
+
"websiteURL": website_url,
|
|
15
|
+
"metadata": metadata,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
data, is_user_agent = self._add_user_agent(data)
|
|
19
|
+
return self._make_request("createTask", data=data).get("taskId")
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
from .capmonster import Proxy, UserAgent
|
|
2
1
|
from typing import Union
|
|
2
|
+
from .capmonster import Proxy, UserAgent
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
class RecaptchaV2EnterpriseTask(UserAgent, Proxy):
|
|
5
6
|
def __init__(self, client_key):
|
|
6
7
|
super(RecaptchaV2EnterpriseTask, self).__init__(client_key)
|
|
7
8
|
|
|
8
9
|
def create_task(self, website_url: str, website_key: str,
|
|
9
|
-
enterprise_payload
|
|
10
|
+
enterprise_payload=None, api_domain: str = None,
|
|
10
11
|
cookies: Union[dict, list, str] = None,
|
|
11
12
|
no_cache: bool = None):
|
|
12
13
|
data = {
|
capmonster_python/utils.py
CHANGED
|
@@ -17,7 +17,7 @@ def check_response():
|
|
|
17
17
|
@wraps(f)
|
|
18
18
|
def wrap(*args, **kwargs):
|
|
19
19
|
rf = f(*args, **kwargs)
|
|
20
|
-
if type(rf)
|
|
20
|
+
if type(rf) is dict:
|
|
21
21
|
if rf.get("errorId") == 0:
|
|
22
22
|
return rf
|
|
23
23
|
else:
|
|
@@ -29,5 +29,7 @@ def check_response():
|
|
|
29
29
|
error_code="CAPMONSTER_API_ERROR",
|
|
30
30
|
error_description="Sometimes can be happen if capmonster_python "
|
|
31
31
|
"servers there is too much intensity")
|
|
32
|
+
|
|
32
33
|
return wrap
|
|
34
|
+
|
|
33
35
|
return checker
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: capmonster_python
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.1
|
|
4
4
|
Summary: capmonster.cloud library for Python
|
|
5
5
|
Home-page: https://github.com/alperensert/capmonster_python
|
|
6
6
|
Author: Alperen Sert
|
|
@@ -29,20 +29,23 @@ Requires-Dist: six
|
|
|
29
29
|
|
|
30
30
|
Capmonster.cloud for Python
|
|
31
31
|
=
|
|
32
|
-
      
|
|
32
|
+
      
|
|
33
33
|
|
|
34
34
|
[Capmonster.cloud](https://capmonster.cloud) package for Python3
|
|
35
35
|
|
|
36
|
-
If you have any problem with usage, [read the documentation](https://alperensert.github.io/capmonster_python)
|
|
36
|
+
If you have any problem with usage, [read the documentation](https://alperensert.github.io/capmonster_python)
|
|
37
|
+
or [create an issue](https://github.com/alperensert/capmonster_python/issues/new)
|
|
37
38
|
|
|
38
39
|
*At least 2x cheaper, up to 30x faster than manual recognition services.*
|
|
39
40
|
|
|
40
41
|
### Installation
|
|
42
|
+
|
|
41
43
|
```
|
|
42
44
|
pip install capmonster_python
|
|
43
45
|
```
|
|
44
46
|
|
|
45
47
|
### Supported captcha types
|
|
48
|
+
|
|
46
49
|
- Image to text
|
|
47
50
|
- Recaptcha v2
|
|
48
51
|
- Recaptcha v2 Enterprise
|
|
@@ -51,6 +54,7 @@ pip install capmonster_python
|
|
|
51
54
|
- HCaptcha
|
|
52
55
|
- GeeTest
|
|
53
56
|
- Turnstile Task
|
|
57
|
+
- Data Dome
|
|
54
58
|
|
|
55
59
|
Usage examples
|
|
56
60
|
-
|
|
@@ -95,7 +99,7 @@ from capmonster_python import GeeTestTask
|
|
|
95
99
|
|
|
96
100
|
capmonster = GeeTestTask("API_KEY")
|
|
97
101
|
task_id = capmonster.create_task("website_url", "gt", "challenge")
|
|
98
|
-
result= capmonster.join_task_result(task_id)
|
|
102
|
+
result = capmonster.join_task_result(task_id)
|
|
99
103
|
print(result.get("challenge"))
|
|
100
104
|
print(result.get("seccode"))
|
|
101
105
|
print(result.get("validate"))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
capmonster_python/__init__.py,sha256=uF6-lErPDl0YVcEfPFg3Lc9SV877BxFEEOPZapqdyp0,415
|
|
2
|
+
capmonster_python/capmonster.py,sha256=zCiK-jzLbCwjAY9qb8pM86PE5W2gQXurCBrcU2uOHR4,8963
|
|
3
|
+
capmonster_python/compleximage.py,sha256=NjsJBR7AlNeo9-1KMxUMCL4PkJm_nL_g8JiFgIk3Xgs,2048
|
|
4
|
+
capmonster_python/datadome.py,sha256=5GQbIiiHN2jYF5il3z7p7_mkac1X7ejx8jkK5-T4RbI,615
|
|
5
|
+
capmonster_python/fun_captcha.py,sha256=bHXsfmrfaDCiV43EiUpr5N8U5VnY0xZFB7876AMDCnA,1207
|
|
6
|
+
capmonster_python/geetest.py,sha256=LUMdvkh4jtOQORkllRQgBn5pjvOlhqlajZtzUppliUA,928
|
|
7
|
+
capmonster_python/hcaptcha.py,sha256=MJB8zfqxYBFsflQVeVngC17NQkUCFuHcqRLBJml6nUQ,1528
|
|
8
|
+
capmonster_python/image_to_text.py,sha256=V268ZeaVfTQHpfHkq5trxMQeLxZskv4r5_3xYjMYejc,1828
|
|
9
|
+
capmonster_python/recaptcha_v2.py,sha256=6fm1Lu3vHMZioHuW475nJ5_nMElgpOKru67x_lPC12c,1035
|
|
10
|
+
capmonster_python/recaptcha_v2_enterprise.py,sha256=Ms8sN4FaA9M16PNkGB5tTP0SBW9H-WQaoh157ewtYG8,1191
|
|
11
|
+
capmonster_python/recaptcha_v3.py,sha256=Yuvvc03FMALSki0WqJqAXGmNVpZqmtqDmhsY7LEP0fE,866
|
|
12
|
+
capmonster_python/turnstile.py,sha256=1mvF6Q5gndzdQhRwanNItN5YUvo_SeM-yLjnx5zMUUg,703
|
|
13
|
+
capmonster_python/utils.py,sha256=kcHEYw-JqDXHPI8baBdRjdV1UKVo8oOriKhqfDgXxYI,1382
|
|
14
|
+
capmonster_python-2.6.1.dist-info/LICENSE,sha256=dsx0VlJZP5DI64ranPoTdQuDmNvrABI9QNm-PctMmM4,1055
|
|
15
|
+
capmonster_python-2.6.1.dist-info/METADATA,sha256=0oKOjW580CndFkwAGngODWfDXmeozaUh9ITmZGpwTq0,4070
|
|
16
|
+
capmonster_python-2.6.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
17
|
+
capmonster_python-2.6.1.dist-info/top_level.txt,sha256=QW5VEUvOJfzDxYpD7fSJtGfUxhM3m7U7LFcZ-wRpU70,18
|
|
18
|
+
capmonster_python-2.6.1.dist-info/RECORD,,
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
capmonster_python/__init__.py,sha256=dZYjtnAYm4TfOaasRoZfjYI7y51pBsVhHFT_tRySMfQ,380
|
|
2
|
-
capmonster_python/capmonster.py,sha256=hq9Lro-2SWMoHaQzH6otEcoFEE_pGt6Hf8zBGKewCOM,7264
|
|
3
|
-
capmonster_python/compleximage.py,sha256=mJq0wVF1HhNBHPwuGJB4W0ak-P7URWphWBzsmqLOtJY,2058
|
|
4
|
-
capmonster_python/fun_captcha.py,sha256=bHXsfmrfaDCiV43EiUpr5N8U5VnY0xZFB7876AMDCnA,1207
|
|
5
|
-
capmonster_python/geetest.py,sha256=LUMdvkh4jtOQORkllRQgBn5pjvOlhqlajZtzUppliUA,928
|
|
6
|
-
capmonster_python/hcaptcha.py,sha256=MJB8zfqxYBFsflQVeVngC17NQkUCFuHcqRLBJml6nUQ,1528
|
|
7
|
-
capmonster_python/image_to_text.py,sha256=V268ZeaVfTQHpfHkq5trxMQeLxZskv4r5_3xYjMYejc,1828
|
|
8
|
-
capmonster_python/recaptcha_v2.py,sha256=6fm1Lu3vHMZioHuW475nJ5_nMElgpOKru67x_lPC12c,1035
|
|
9
|
-
capmonster_python/recaptcha_v2_enterprise.py,sha256=5svDHX7aVfdOwdvmkZ72eMoryWNHbTWMiPXbpZEmOgw,1192
|
|
10
|
-
capmonster_python/recaptcha_v3.py,sha256=Yuvvc03FMALSki0WqJqAXGmNVpZqmtqDmhsY7LEP0fE,866
|
|
11
|
-
capmonster_python/turnstile.py,sha256=1mvF6Q5gndzdQhRwanNItN5YUvo_SeM-yLjnx5zMUUg,703
|
|
12
|
-
capmonster_python/utils.py,sha256=10IAtWI_k92nTxbKwCdGTh_14U7vXZyXbQyteN0zDkM,1380
|
|
13
|
-
capmonster_python-2.5.0.dist-info/LICENSE,sha256=dsx0VlJZP5DI64ranPoTdQuDmNvrABI9QNm-PctMmM4,1055
|
|
14
|
-
capmonster_python-2.5.0.dist-info/METADATA,sha256=Z6C4bcZ4qhUQgHmUZ3mkBda9T_APWMQeUx3kDeLFgG0,4056
|
|
15
|
-
capmonster_python-2.5.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
16
|
-
capmonster_python-2.5.0.dist-info/top_level.txt,sha256=QW5VEUvOJfzDxYpD7fSJtGfUxhM3m7U7LFcZ-wRpU70,18
|
|
17
|
-
capmonster_python-2.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|