python3-capsolver 1.0.0a0__tar.gz → 1.0.2__tar.gz

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 (49) hide show
  1. {python3_capsolver-1.0.0a0/src/python3_capsolver.egg-info → python3_capsolver-1.0.2}/PKG-INFO +2 -1
  2. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/README.md +1 -0
  3. python3_capsolver-1.0.2/src/python3_capsolver/__version__.py +1 -0
  4. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/cloudflare.py +36 -0
  5. python3_capsolver-1.0.2/src/python3_capsolver/control.py +431 -0
  6. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/aio_captcha_instrument.py +13 -11
  7. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/base.py +13 -14
  8. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/captcha_instrument.py +75 -2
  9. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/const.py +0 -6
  10. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/enum.py +2 -0
  11. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/serializer.py +1 -1
  12. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/sio_captcha_instrument.py +6 -6
  13. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/datadome_slider.py +22 -0
  14. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/friendly_captcha.py +36 -0
  15. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/image_to_text.py +6 -38
  16. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/mt_captcha.py +17 -0
  17. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/vision_engine.py +4 -35
  18. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/yandex.py +23 -3
  19. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2/src/python3_capsolver.egg-info}/PKG-INFO +2 -1
  20. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver.egg-info/SOURCES.txt +6 -1
  21. python3_capsolver-1.0.2/tests/test_aws_waf.py +115 -0
  22. python3_capsolver-1.0.0a0/tests/test_aws_waf.py → python3_capsolver-1.0.2/tests/test_cloudflare.py +7 -8
  23. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_core.py +10 -10
  24. python3_capsolver-1.0.2/tests/test_datadome.py +33 -0
  25. python3_capsolver-1.0.2/tests/test_friendly.py +33 -0
  26. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_image_to_text.py +3 -2
  27. python3_capsolver-1.0.2/tests/test_vision_engine.py +23 -0
  28. python3_capsolver-1.0.2/tests/test_yandex.py +33 -0
  29. python3_capsolver-1.0.0a0/src/python3_capsolver/__version__.py +0 -1
  30. python3_capsolver-1.0.0a0/src/python3_capsolver/control.py +0 -68
  31. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/LICENSE +0 -0
  32. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/MANIFEST.in +0 -0
  33. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/pyproject.toml +0 -0
  34. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/setup.cfg +0 -0
  35. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/__init__.py +0 -0
  36. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/aws_waf.py +0 -0
  37. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/__init__.py +0 -0
  38. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/context_instr.py +0 -0
  39. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/core/utils.py +0 -0
  40. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/gee_test.py +0 -0
  41. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver/recaptcha.py +0 -0
  42. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver.egg-info/dependency_links.txt +0 -0
  43. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver.egg-info/requires.txt +0 -0
  44. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/src/python3_capsolver.egg-info/top_level.txt +0 -0
  45. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_control.py +0 -0
  46. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_gee_test.py +0 -0
  47. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_instrument.py +0 -0
  48. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_mt_captcha.py +0 -0
  49. {python3_capsolver-1.0.0a0 → python3_capsolver-1.0.2}/tests/test_recaptcha.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: python3-capsolver
3
- Version: 1.0.0a0
3
+ Version: 1.0.2
4
4
  Summary: Python 3.8+ Capsolver library with AIO module.
5
5
  Author-email: AndreiDrang <python-captcha@pm.me>
6
6
  License: MIT License
@@ -44,6 +44,7 @@ Requires-Dist: tenacity<10,>=8
44
44
  [![Downloads](https://static.pepy.tech/badge/python3-capsolver/month)](https://pepy.tech/project/python3-capsolver)
45
45
  [![Static Badge](https://img.shields.io/badge/docs-Sphinx-green?label=Documentation&labelColor=gray)](https://andreidrang.github.io/python3-capsolver/)
46
46
 
47
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3c30167b5fb37a0775ea/maintainability)](https://codeclimate.com/github/AndreiDrang/python3-capsolver/maintainability)
47
48
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/323d4eda0fe1477bbea8fe8902b9e97e)](https://www.codacy.com/gh/AndreiDrang/python3-capsolver/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AndreiDrang/python3-capsolver&amp;utm_campaign=Badge_Grade)
48
49
  [![codecov](https://codecov.io/gh/AndreiDrang/python3-capsolver/branch/main/graph/badge.svg?token=2L4VVIF4G8)](https://codecov.io/gh/AndreiDrang/python3-capsolver)
49
50
 
@@ -9,6 +9,7 @@
9
9
  [![Downloads](https://static.pepy.tech/badge/python3-capsolver/month)](https://pepy.tech/project/python3-capsolver)
10
10
  [![Static Badge](https://img.shields.io/badge/docs-Sphinx-green?label=Documentation&labelColor=gray)](https://andreidrang.github.io/python3-capsolver/)
11
11
 
12
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3c30167b5fb37a0775ea/maintainability)](https://codeclimate.com/github/AndreiDrang/python3-capsolver/maintainability)
12
13
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/323d4eda0fe1477bbea8fe8902b9e97e)](https://www.codacy.com/gh/AndreiDrang/python3-capsolver/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AndreiDrang/python3-capsolver&amp;utm_campaign=Badge_Grade)
13
14
  [![codecov](https://codecov.io/gh/AndreiDrang/python3-capsolver/branch/main/graph/badge.svg?token=2L4VVIF4G8)](https://codecov.io/gh/AndreiDrang/python3-capsolver)
14
15
 
@@ -0,0 +1 @@
1
+ __version__ = "1.0.2"
@@ -79,6 +79,42 @@ class Cloudflare(CaptchaParams):
79
79
  }
80
80
  }
81
81
 
82
+ >>> import asyncio
83
+ >>> from python3_capsolver.cloudflare import Cloudflare
84
+ >>> from python3_capsolver.core.enum import CaptchaTypeEnm
85
+ >>> asyncio.run(Cloudflare(api_key="CAI-12345....",
86
+ ... captcha_type=CaptchaTypeEnm.AntiCloudflareTask)
87
+ ... .aio_captcha_handler(task_payload={
88
+ ... "websiteURL": "https://www.yourwebsite.com",
89
+ ... "proxy": "ip:port:user:pass",
90
+ ... }))
91
+ {
92
+ "errorId":0,
93
+ "errorCode":"None",
94
+ "errorDescription":"None",
95
+ "taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
96
+ "status":"ready",
97
+ "solution":{
98
+ "cookies": "cf_clearance=_VPxxxx",
99
+ "headers": {
100
+ "sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
101
+ "sec-ch-ua-platform": "\"Windows\"",
102
+ "accept": "text/html,axxxx",
103
+ "User-Agent": "Mozilla/5.0xxxx",
104
+ "sec-ch-ua-mobile": "?0",
105
+ "sec-fetch-user": "?1",
106
+ "referer": "https://www.yourwebsite.com",
107
+ "Sec-Fetch-Dest": "document",
108
+ "Sec-Fetch-Mode": "navigate",
109
+ "Sec-Fetch-Site": "same-origin",
110
+ "accept-language": "en",
111
+ },
112
+ "page_url": "https://www.yourwebsite.com",
113
+ "proxy": "your proxyxxxx",
114
+ "token": "_VPCTZXP5bhinxxxx"
115
+ }
116
+ }
117
+
82
118
  Notes:
83
119
  https://docs.capsolver.com/en/guide/captcha/cloudflare_turnstile/
84
120
 
@@ -0,0 +1,431 @@
1
+ from typing import Dict
2
+
3
+ from .core.base import CaptchaParams
4
+ from .core.enum import CaptchaTypeEnm, EndpointPostfixEnm
5
+ from .core.aio_captcha_instrument import AIOCaptchaInstrument
6
+ from .core.sio_captcha_instrument import SIOCaptchaInstrument
7
+
8
+ __all__ = ("Control",)
9
+
10
+
11
+ class Control(CaptchaParams):
12
+ """
13
+ The class is used to work with Capsolver control methods.
14
+
15
+ Args:
16
+ api_key: Capsolver API key
17
+
18
+ Notes:
19
+ https://docs.capsolver.com/en/guide/api-getbalance/
20
+
21
+ https://docs.capsolver.com/en/guide/api-gettaskresult/
22
+
23
+ https://docs.capsolver.com/en/guide/api-createtask/
24
+
25
+ https://docs.capsolver.com/en/guide/api-getToken/
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ api_key: str,
31
+ ):
32
+ super().__init__(api_key=api_key, captcha_type=CaptchaTypeEnm.Control)
33
+
34
+ def get_balance(self) -> dict:
35
+ """
36
+ Synchronous method to view the balance
37
+
38
+ Examples:
39
+ >>> from python3_capsolver.control import Control
40
+ >>> Control(api_key="CAI-1324...").get_balance()
41
+ {'balance': 48.6361, 'errorId': 0, 'packages': []}
42
+
43
+ Returns:
44
+ Dict with full server response
45
+
46
+ Notes:
47
+ Check class docstring for more info
48
+ """
49
+ self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
50
+ return self._captcha_handling_instrument.send_post_request(
51
+ session=self._captcha_handling_instrument.session,
52
+ url_postfix=EndpointPostfixEnm.GET_BALANCE,
53
+ payload={"clientKey": self.create_task_payload.clientKey},
54
+ )
55
+
56
+ async def aio_get_balance(self) -> dict:
57
+ """
58
+ Asynchronous method to view the balance
59
+
60
+ Examples:
61
+ >>> import asyncio
62
+ >>> from python3_capsolver.control import Control
63
+ >>> asyncio.run(Control(api_key="CAI-1324...").aio_get_balance())
64
+ {'balance': 48.6361, 'errorId': 0, 'packages': []}
65
+
66
+ Returns:
67
+ Dict with full server response
68
+
69
+ Notes:
70
+ Check class docstring for more info
71
+ """
72
+ return await AIOCaptchaInstrument.send_post_request(
73
+ url_postfix=EndpointPostfixEnm.GET_BALANCE,
74
+ payload={"clientKey": self.create_task_payload.clientKey},
75
+ )
76
+
77
+ def create_task(self, task_payload: Dict) -> dict:
78
+ """
79
+ Synchronous method to send custom ``createTask`` request.
80
+
81
+ This is the custom analog for prepared captcha solving classes.
82
+ With this method u can create task with custom type and get
83
+ response with task solution or task ID (depends on task type).
84
+ The main difference with ``captcha_handler`` methods
85
+ - there is no retries logic and other sugar.
86
+
87
+ Args:
88
+ task_payload: Some additional parameters that will be used in creating the task
89
+ and will be passed to the payload under ``task`` key.
90
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
91
+ more info in service docs
92
+
93
+ Examples:
94
+ >>> from python3_capsolver.control import Control
95
+ >>> Control(api_key="CAI-1324...").get_task_result(
96
+ ... task_payload={
97
+ ... "type": "VisionEngine",
98
+ ... "image": "base64_image_body",
99
+ ... "question": "click on the object",
100
+ ... "module": "space_detection",
101
+ ... }
102
+ ... )
103
+ {
104
+ "errorId": 0,
105
+ "errorCode":"None",
106
+ "errorDescription":"None",
107
+ "taskId": "db0a3153-xxxx",
108
+ "status":"ready",
109
+ "solution": {
110
+ "userAgent": "xxx",
111
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
112
+ },
113
+ }
114
+
115
+ Returns:
116
+ Dict with full server response
117
+
118
+ Notes:
119
+ https://docs.capsolver.com/en/guide/api-createtask/
120
+ """
121
+ self.task_params.update(task_payload)
122
+ self.create_task_payload.task = self.task_params
123
+ self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
124
+ return self._captcha_handling_instrument.send_post_request(
125
+ session=self._captcha_handling_instrument.session,
126
+ url_postfix=EndpointPostfixEnm.CREATE_TASK,
127
+ payload=self.create_task_payload.to_dict(),
128
+ )
129
+
130
+ async def aio_create_task(self, task_payload: Dict) -> dict:
131
+ """
132
+ Asynchronous method to send custom ``createTask`` request.
133
+
134
+ This is the custom analog for prepared captcha solving classes.
135
+ With this method u can create task with custom type and get
136
+ response with task solution or task ID (depends on task type).
137
+ The main difference with ``captcha_handler`` methods
138
+ - there is no retries logic and other sugar.
139
+
140
+ Args:
141
+ task_payload: Some additional parameters that will be used in creating the task
142
+ and will be passed to the payload under ``task`` key.
143
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
144
+ more info in service docs
145
+
146
+ Examples:
147
+ >>> import asyncio
148
+ >>> from python3_capsolver.control import Control
149
+ >>> asyncio.run(Control(api_key="CAI-1324...")
150
+ ... .aio_create_task(
151
+ ... task_payload={
152
+ ... "type": "VisionEngine",
153
+ ... "image": "base64_image_body",
154
+ ... "question": "click on the unique object",
155
+ ... "module": "space_detection",
156
+ ... }
157
+ ... ))
158
+ {
159
+ "errorId": 0,
160
+ "errorCode":"None",
161
+ "errorDescription":"None",
162
+ "taskId": "db0a3153-xxxx",
163
+ "status":"ready",
164
+ "solution": {
165
+ "userAgent": "xxx",
166
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
167
+ },
168
+ }
169
+
170
+ Returns:
171
+ Dict with full server response
172
+
173
+ Notes:
174
+ https://docs.capsolver.com/en/guide/api-createtask/
175
+ """
176
+ self.task_params.update(task_payload)
177
+ self.create_task_payload.task = self.task_params
178
+ return await AIOCaptchaInstrument.send_post_request(
179
+ url_postfix=EndpointPostfixEnm.CREATE_TASK,
180
+ payload=self.create_task_payload.to_dict(),
181
+ )
182
+
183
+ def get_task_result(self, task_id: str) -> dict:
184
+ """
185
+ Synchronous method to send ``getTaskResult`` request
186
+
187
+ Args:
188
+ task_id: Task ID
189
+
190
+ Examples:
191
+ >>> from python3_capsolver.control import Control
192
+ >>> Control(api_key="CAI-1324...").get_task_result(task_id="db0a3153-xxxx")
193
+ {
194
+ "errorId": 0,
195
+ "errorCode":"None",
196
+ "errorDescription":"None",
197
+ "taskId": "db0a3153-xxxx",
198
+ "status":"ready",
199
+ "solution": {
200
+ "userAgent": "xxx",
201
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
202
+ },
203
+ }
204
+
205
+ Returns:
206
+ Dict with full server response
207
+
208
+ Notes:
209
+ https://docs.capsolver.com/en/guide/api-gettaskresult/
210
+ """
211
+ self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
212
+ return self._captcha_handling_instrument.send_post_request(
213
+ session=self._captcha_handling_instrument.session,
214
+ url_postfix=EndpointPostfixEnm.GET_TASK_RESULT,
215
+ payload={"clientKey": self.create_task_payload.clientKey, "taskId": task_id},
216
+ )
217
+
218
+ async def aio_get_task_result(self, task_id: str) -> dict:
219
+ """
220
+ Synchronous method to send ``getTaskResult`` request
221
+
222
+ Args:
223
+ task_id: Task ID
224
+
225
+ Examples:
226
+ >>> import asyncio
227
+ >>> from python3_capsolver.control import Control
228
+ >>> asyncio.run(Control(api_key="CAI-1324...")
229
+ ... .aio_get_task_result(task_id="db0a3153-xxxx"))
230
+ {
231
+ "errorId": 0,
232
+ "errorCode":"None",
233
+ "errorDescription":"None",
234
+ "taskId": "db0a3153-xxxx",
235
+ "status":"ready",
236
+ "solution": {
237
+ "userAgent": "xxx",
238
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
239
+ },
240
+ }
241
+
242
+ Returns:
243
+ Dict with full server response
244
+
245
+ Notes:
246
+ https://docs.capsolver.com/en/guide/api-gettaskresult/
247
+ """
248
+ return await AIOCaptchaInstrument.send_post_request(
249
+ url_postfix=EndpointPostfixEnm.GET_TASK_RESULT,
250
+ payload={"clientKey": self.create_task_payload.clientKey, "taskId": task_id},
251
+ )
252
+
253
+ def get_token(self, task_payload: Dict) -> dict:
254
+ """
255
+ Synchronous method to send custom ``getToken`` request.
256
+
257
+ Args:
258
+ task_payload: Some additional parameters that will be used in creating the task
259
+ and will be passed to the payload under ``task`` key.
260
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
261
+ more info in service docs
262
+
263
+ Examples:
264
+ >>> from python3_capsolver.control import Control
265
+ >>> Control(api_key="CAI-1324...").get_token(
266
+ ... task_payload={
267
+ ... "type": "ReCaptchaV3TaskProxyLess",
268
+ ... "websiteURL": "https://demo.com/",
269
+ ... "websiteKey": "6LcpsXsnAAAbbAcxxxx"
270
+ ... }
271
+ ... )
272
+ {
273
+ "errorId": 0,
274
+ "errorCode":"None",
275
+ "errorDescription":"None",
276
+ "taskId": "db0a3153-xxxx",
277
+ "status":"ready",
278
+ "solution": {
279
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
280
+ },
281
+ }
282
+
283
+ Returns:
284
+ Dict with full server response
285
+
286
+ Notes:
287
+ https://docs.capsolver.com/en/guide/api-getToken/
288
+ """
289
+ self.task_params.update(task_payload)
290
+ self.create_task_payload.task = self.task_params
291
+ self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
292
+ return self._captcha_handling_instrument.send_post_request(
293
+ session=self._captcha_handling_instrument.session,
294
+ url_postfix=EndpointPostfixEnm.GET_TOKEN,
295
+ payload=self.create_task_payload.to_dict(),
296
+ )
297
+
298
+ async def aio_get_token(self, task_payload: Dict) -> dict:
299
+ """
300
+ Asynchronous method to send custom ``getToken`` request.
301
+
302
+ Args:
303
+ task_payload: Some additional parameters that will be used in creating the task
304
+ and will be passed to the payload under ``task`` key.
305
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
306
+ more info in service docs
307
+
308
+ Examples:
309
+ >>> import asyncio
310
+ >>> from python3_capsolver.control import Control
311
+ >>> asyncio.run(Control(api_key="CAI-1324...")
312
+ ... .aio_get_token(
313
+ ... task_payload={
314
+ ... "type": "ReCaptchaV3TaskProxyLess",
315
+ ... "websiteURL": "https://demo.com/",
316
+ ... "websiteKey": "6LcpsXsnAAAbbAcxxxx"
317
+ ... }
318
+ ... ))
319
+ {
320
+ "errorId": 0,
321
+ "errorCode":"None",
322
+ "errorDescription":"None",
323
+ "taskId": "db0a3153-xxxx",
324
+ "status":"ready",
325
+ "solution": {
326
+ "gRecaptchaResponse": "03AGdBq25SxXT-pmSeBXjzScW-xxxx"
327
+ },
328
+ }
329
+
330
+ Returns:
331
+ Dict with full server response
332
+
333
+ Notes:
334
+ https://docs.capsolver.com/en/guide/api-getToken/
335
+ """
336
+ self.task_params.update(task_payload)
337
+ self.create_task_payload.task = self.task_params
338
+ return await AIOCaptchaInstrument.send_post_request(
339
+ url_postfix=EndpointPostfixEnm.GET_TOKEN,
340
+ payload=self.create_task_payload.to_dict(),
341
+ )
342
+
343
+ def feedback_task(self, task_id: str, result_payload: Dict) -> dict:
344
+ """
345
+ Synchronous method to send custom ``feedbackTask`` request.
346
+
347
+ Args:
348
+ task_id: Task ID to report
349
+ result_payload: Some additional parameters that will be used in creating the task
350
+ and will be passed to the payload under ``result`` key.
351
+ Like ``invalid``, ``code``, ``message`` and etc.
352
+ more info in service docs
353
+
354
+ Examples:
355
+ >>> from python3_capsolver.control import Control
356
+ >>> Control(api_key="CAI-1324...").feedback_task(
357
+ ... task_id="db0a3153-xxxx",
358
+ ... result_payload={
359
+ ... "invalid": True,
360
+ ... "code": 1001,
361
+ ... "message": "invalid token"
362
+ ... }
363
+ ... )
364
+ {
365
+ "errorId": 0,
366
+ "errorCode":"None",
367
+ "errorDescription":"None",
368
+ "message": "okay"
369
+ }
370
+
371
+ Returns:
372
+ Dict with full server response
373
+
374
+ Notes:
375
+ https://docs.capsolver.com/en/guide/api-feedback/
376
+ """
377
+ self.task_params.update(result_payload)
378
+ dict_payload = self.create_task_payload.to_dict()
379
+ dict_payload.update({"result": self.task_params, "taskId": task_id})
380
+
381
+ self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
382
+ return self._captcha_handling_instrument.send_post_request(
383
+ session=self._captcha_handling_instrument.session,
384
+ url_postfix=EndpointPostfixEnm.GET_TOKEN,
385
+ payload=dict_payload,
386
+ )
387
+
388
+ async def aio_feedback_task(self, task_id: str, result_payload: Dict) -> dict:
389
+ """
390
+ Asynchronous method to send custom ``feedbackTask`` request.
391
+
392
+ Args:
393
+ task_id: Task ID to report
394
+ result_payload: Some additional parameters that will be used in creating the task
395
+ and will be passed to the payload under ``result`` key.
396
+ Like ``invalid``, ``code``, ``message`` and etc.
397
+ more info in service docs
398
+
399
+ Examples:
400
+ >>> import asyncio
401
+ >>> from python3_capsolver.control import Control
402
+ >>> asyncio.run(Control(api_key="CAI-1324...")
403
+ ... .aio_feedback_task(
404
+ ... task_id="db0a3153-xxxx",
405
+ ... result_payload={
406
+ ... "invalid": True,
407
+ ... "code": 1001,
408
+ ... "message": "invalid token"
409
+ ... }
410
+ ... ))
411
+ {
412
+ "errorId": 0,
413
+ "errorCode":"None",
414
+ "errorDescription":"None",
415
+ "message": "okay"
416
+ }
417
+
418
+ Returns:
419
+ Dict with full server response
420
+
421
+ Notes:
422
+ https://docs.capsolver.com/en/guide/api-feedback/
423
+ """
424
+ self.task_params.update(result_payload)
425
+ dict_payload = self.create_task_payload.to_dict()
426
+ dict_payload.update({"result": self.task_params, "taskId": task_id})
427
+
428
+ return await AIOCaptchaInstrument.send_post_request(
429
+ url_postfix=EndpointPostfixEnm.GET_TOKEN,
430
+ payload=dict_payload,
431
+ )
@@ -6,15 +6,15 @@ from urllib import parse
6
6
  import aiohttp
7
7
 
8
8
  from .enum import ResponseStatusEnm, EndpointPostfixEnm
9
- from .const import REQUEST_URL, VALID_STATUS_CODES, GET_BALANCE_POSTFIX
9
+ from .const import REQUEST_URL, VALID_STATUS_CODES
10
10
  from .utils import attempts_generator
11
11
  from .serializer import CaptchaResponseSer
12
- from .captcha_instrument import CaptchaInstrument
12
+ from .captcha_instrument import CaptchaInstrumentBase
13
13
 
14
14
  __all__ = ("AIOCaptchaInstrument",)
15
15
 
16
16
 
17
- class AIOCaptchaInstrument(CaptchaInstrument):
17
+ class AIOCaptchaInstrument(CaptchaInstrumentBase):
18
18
  """
19
19
  Instrument for working with async captcha
20
20
  """
@@ -84,22 +84,24 @@ class AIOCaptchaInstrument(CaptchaInstrument):
84
84
  # if captcha just created or in processing now - wait
85
85
  await asyncio.sleep(self.captcha_params.sleep_time)
86
86
 
87
- # default response if server is silent
88
- self.result.errorId = 1
89
- self.result.errorCode = self.CAPTCHA_UNSOLVABLE
90
- self.result.errorDescription = "Captcha not recognized"
91
- self.result.taskId = self.created_task_data.taskId
92
- self.result.status = ResponseStatusEnm.Failed
87
+ # default response if server is silent
88
+ self.result.errorId = 1
89
+ self.result.errorCode = self.CAPTCHA_UNSOLVABLE
90
+ self.result.errorDescription = self.CAPTCHA_UNSOLVABLE_DESCRIPTION
91
+ self.result.taskId = self.created_task_data.taskId
92
+ self.result.status = ResponseStatusEnm.Failed
93
93
 
94
94
  @staticmethod
95
- async def send_post_request(payload: Optional[dict] = None, url_postfix: str = GET_BALANCE_POSTFIX) -> dict:
95
+ async def send_post_request(
96
+ payload: Optional[dict] = None, url_postfix: EndpointPostfixEnm = EndpointPostfixEnm.GET_BALANCE
97
+ ) -> dict:
96
98
  """
97
99
  Function send ASYNC request to service and wait for result
98
100
  """
99
101
 
100
102
  async with aiohttp.ClientSession() as session:
101
103
  try:
102
- async with session.post(parse.urljoin(REQUEST_URL, url_postfix), json=payload) as resp:
104
+ async with session.post(parse.urljoin(REQUEST_URL, url_postfix.value), json=payload) as resp:
103
105
  if resp.status == 200:
104
106
  return await resp.json()
105
107
  else:
@@ -1,12 +1,10 @@
1
- from typing import Dict
2
-
3
- from python3_capsolver.core.enum import CaptchaTypeEnm
4
- from python3_capsolver.core.serializer import TaskSer
1
+ from typing import Any, Dict
5
2
 
3
+ from .enum import CaptchaTypeEnm
6
4
  from .const import REQUEST_URL
7
- from .serializer import RequestCreateTaskSer, RequestGetTaskResultSer
5
+ from .serializer import TaskSer, RequestCreateTaskSer, RequestGetTaskResultSer
8
6
  from .context_instr import AIOContextManager, SIOContextManager
9
- from .captcha_instrument import CaptchaInstrument
7
+ from .captcha_instrument import CaptchaInstrumentBase
10
8
  from .aio_captcha_instrument import AIOCaptchaInstrument
11
9
  from .sio_captcha_instrument import SIOCaptchaInstrument
12
10
 
@@ -38,18 +36,18 @@ class CaptchaParams(SIOContextManager, AIOContextManager):
38
36
  # prepare `get task result` payload
39
37
  self.get_result_params = RequestGetTaskResultSer(clientKey=api_key)
40
38
  self.request_url = request_url
41
- self._captcha_handling_instrument = CaptchaInstrument()
39
+ self._captcha_handling_instrument = CaptchaInstrumentBase()
42
40
  self.sleep_time = sleep_time
43
41
 
44
- def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
42
+ def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
45
43
  """
46
44
  Synchronous method for captcha solving
47
45
 
48
46
  Args:
49
47
  task_payload: Some additional parameters that will be used in creating the task
50
- and will be passed to the payload under ``task`` key.
51
- Like ``proxyLogin``, ``proxyPassword`` and etc. - more info in service docs
52
-
48
+ and will be passed to the payload under ``task`` key.
49
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
50
+ more info in service docs
53
51
 
54
52
  Returns:
55
53
  Dict with full server response
@@ -61,14 +59,15 @@ class CaptchaParams(SIOContextManager, AIOContextManager):
61
59
  self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
62
60
  return self._captcha_handling_instrument.processing_captcha()
63
61
 
64
- async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
62
+ async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
65
63
  """
66
64
  Asynchronous method for captcha solving
67
65
 
68
66
  Args:
69
67
  task_payload: Some additional parameters that will be used in creating the task
70
- and will be passed to the payload under ``task`` key.
71
- Like ``proxyLogin``, ``proxyPassword`` and etc. - more info in service docs
68
+ and will be passed to the payload under ``task`` key.
69
+ Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
70
+ more info in service docs
72
71
 
73
72
  Returns:
74
73
  Dict with full server response