python3-capsolver 0.9.4__tar.gz → 1.0.1__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.
- {python3_capsolver-0.9.4/src/python3_capsolver.egg-info → python3_capsolver-1.0.1}/PKG-INFO +12 -12
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/README.md +9 -9
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/pyproject.toml +2 -1
- python3_capsolver-1.0.1/src/python3_capsolver/__version__.py +1 -0
- python3_capsolver-1.0.1/src/python3_capsolver/aws_waf.py +138 -0
- python3_capsolver-1.0.1/src/python3_capsolver/cloudflare.py +131 -0
- python3_capsolver-1.0.1/src/python3_capsolver/control.py +68 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/aio_captcha_instrument.py +109 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/base.py +82 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/captcha_instrument.py +145 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/const.py +27 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/context_instr.py +25 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/enum.py +84 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/serializer.py +62 -0
- python3_capsolver-1.0.1/src/python3_capsolver/core/sio_captcha_instrument.py +116 -0
- python3_capsolver-0.9.4/src/python3_capsolver/core/config.py → python3_capsolver-1.0.1/src/python3_capsolver/core/utils.py +1 -10
- python3_capsolver-1.0.1/src/python3_capsolver/datadome_slider.py +75 -0
- python3_capsolver-1.0.1/src/python3_capsolver/friendly_captcha.py +105 -0
- python3_capsolver-1.0.1/src/python3_capsolver/gee_test.py +76 -0
- python3_capsolver-1.0.1/src/python3_capsolver/image_to_text.py +121 -0
- python3_capsolver-1.0.1/src/python3_capsolver/mt_captcha.py +64 -0
- python3_capsolver-1.0.1/src/python3_capsolver/recaptcha.py +81 -0
- python3_capsolver-1.0.1/src/python3_capsolver/vision_engine.py +102 -0
- python3_capsolver-1.0.1/src/python3_capsolver/yandex.py +73 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1/src/python3_capsolver.egg-info}/PKG-INFO +12 -12
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver.egg-info/SOURCES.txt +16 -14
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver.egg-info/requires.txt +1 -1
- python3_capsolver-1.0.1/tests/test_aws_waf.py +115 -0
- python3_capsolver-1.0.1/tests/test_cloudflare.py +36 -0
- python3_capsolver-1.0.1/tests/test_control.py +38 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/tests/test_core.py +23 -30
- python3_capsolver-1.0.1/tests/test_datadome.py +33 -0
- python3_capsolver-1.0.1/tests/test_friendly.py +33 -0
- python3_capsolver-1.0.1/tests/test_gee_test.py +27 -0
- python3_capsolver-1.0.1/tests/test_image_to_text.py +58 -0
- python3_capsolver-1.0.1/tests/test_instrument.py +57 -0
- python3_capsolver-1.0.1/tests/test_mt_captcha.py +33 -0
- python3_capsolver-1.0.1/tests/test_recaptcha.py +43 -0
- python3_capsolver-1.0.1/tests/test_vision_engine.py +23 -0
- python3_capsolver-1.0.1/tests/test_yandex.py +33 -0
- python3_capsolver-0.9.4/src/python3_capsolver/__version__.py +0 -1
- python3_capsolver-0.9.4/src/python3_capsolver/akamai.py +0 -192
- python3_capsolver-0.9.4/src/python3_capsolver/aws_waf.py +0 -111
- python3_capsolver-0.9.4/src/python3_capsolver/binance.py +0 -112
- python3_capsolver-0.9.4/src/python3_capsolver/cloudflare.py +0 -114
- python3_capsolver-0.9.4/src/python3_capsolver/control.py +0 -66
- python3_capsolver-0.9.4/src/python3_capsolver/core/base.py +0 -227
- python3_capsolver-0.9.4/src/python3_capsolver/core/enum.py +0 -139
- python3_capsolver-0.9.4/src/python3_capsolver/core/serializer.py +0 -155
- python3_capsolver-0.9.4/src/python3_capsolver/cyber_si_ara.py +0 -128
- python3_capsolver-0.9.4/src/python3_capsolver/datadome_slider.py +0 -103
- python3_capsolver-0.9.4/src/python3_capsolver/fun_captcha.py +0 -251
- python3_capsolver-0.9.4/src/python3_capsolver/gee_test.py +0 -108
- python3_capsolver-0.9.4/src/python3_capsolver/hcaptcha.py +0 -197
- python3_capsolver-0.9.4/src/python3_capsolver/image_to_text.py +0 -151
- python3_capsolver-0.9.4/src/python3_capsolver/imperva.py +0 -120
- python3_capsolver-0.9.4/src/python3_capsolver/mt_captcha.py +0 -123
- python3_capsolver-0.9.4/src/python3_capsolver/recaptcha.py +0 -145
- python3_capsolver-0.9.4/tests/test_akamai.py +0 -106
- python3_capsolver-0.9.4/tests/test_binance.py +0 -83
- python3_capsolver-0.9.4/tests/test_cloudflare.py +0 -73
- python3_capsolver-0.9.4/tests/test_control.py +0 -45
- python3_capsolver-0.9.4/tests/test_datadome_slider.py +0 -96
- python3_capsolver-0.9.4/tests/test_fun_captcha.py +0 -302
- python3_capsolver-0.9.4/tests/test_gee_test.py +0 -207
- python3_capsolver-0.9.4/tests/test_hcaptcha.py +0 -294
- python3_capsolver-0.9.4/tests/test_image_to_text.py +0 -80
- python3_capsolver-0.9.4/tests/test_imperva.py +0 -93
- python3_capsolver-0.9.4/tests/test_mt_captcha.py +0 -94
- python3_capsolver-0.9.4/tests/test_recaptcha.py +0 -284
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/LICENSE +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/MANIFEST.in +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/setup.cfg +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver/__init__.py +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver/core/__init__.py +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver.egg-info/dependency_links.txt +0 -0
- {python3_capsolver-0.9.4 → python3_capsolver-1.0.1}/src/python3_capsolver.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: python3-capsolver
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.1
|
|
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
|
|
@@ -30,18 +30,19 @@ Description-Content-Type: text/markdown
|
|
|
30
30
|
License-File: LICENSE
|
|
31
31
|
Requires-Dist: requests>=2.21.0
|
|
32
32
|
Requires-Dist: aiohttp>=3.9.2
|
|
33
|
-
Requires-Dist:
|
|
33
|
+
Requires-Dist: msgspec<0.20,>=0.18
|
|
34
34
|
Requires-Dist: tenacity<10,>=8
|
|
35
35
|
|
|
36
36
|
# python3-capsolver
|
|
37
37
|
|
|
38
|
-
](https://vyjava.xyz/dashboard/image/109278aa-961a-4503-bed0-0a9c838dcef2)
|
|
39
39
|
|
|
40
40
|
<hr>
|
|
41
41
|
|
|
42
42
|
[](https://badge.fury.io/py/python3-capsolver)
|
|
43
43
|
[](https://badge.fury.io/py/python3-capsolver)
|
|
44
44
|
[](https://pepy.tech/project/python3-capsolver)
|
|
45
|
+
[](https://andreidrang.github.io/python3-capsolver/)
|
|
45
46
|
|
|
46
47
|
[](https://codeclimate.com/github/AndreiDrang/python3-capsolver/maintainability)
|
|
47
48
|
[](https://www.codacy.com/gh/AndreiDrang/python3-capsolver/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AndreiDrang/python3-capsolver&utm_campaign=Badge_Grade)
|
|
@@ -55,17 +56,10 @@ Requires-Dist: tenacity<10,>=8
|
|
|
55
56
|
|
|
56
57
|
|
|
57
58
|
Python 3 library for [Capsolver](https://dashboard.capsolver.com/passport/register?inviteCode=kQTn-tG07Jb1) service API.
|
|
58
|
-
|
|
59
59
|
Tested on UNIX based OS.
|
|
60
60
|
|
|
61
61
|
The library is intended for software developers and is used to work with the [Capsolver](https://dashboard.capsolver.com/passport/register?inviteCode=kQTn-tG07Jb1) service API.
|
|
62
62
|
|
|
63
|
-
***
|
|
64
|
-
|
|
65
|
-
If you have any questions, please send a message to the [Telegram](https://t.me/pythoncaptcha) chat room.
|
|
66
|
-
|
|
67
|
-
Or email python-captcha@pm.me
|
|
68
|
-
|
|
69
63
|
## How to install?
|
|
70
64
|
|
|
71
65
|
We recommend using the latest version of Python. `python3-capsolver` supports Python 3.7+.
|
|
@@ -93,4 +87,10 @@ Check [releases page](https://github.com/AndreiDrang/python3-capsolver/releases)
|
|
|
93
87
|
|
|
94
88
|
### How to get API Key to work with the library
|
|
95
89
|
1. On the page - https://dashboard.capsolver.com/overview/user-center
|
|
96
|
-
2. Find it: 
|
|
90
|
+
2. Find it: [](https://vyjava.xyz/dashboard/image/ae8d4fbf-7451-441d-8984-79b1a7adbe27)
|
|
91
|
+
|
|
92
|
+
### Contacts
|
|
93
|
+
|
|
94
|
+
If you have any questions, please send a message to the [Telegram](https://t.me/pythoncaptcha) chat room.
|
|
95
|
+
|
|
96
|
+
Or email python-captcha@pm.me
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# python3-capsolver
|
|
2
2
|
|
|
3
|
-
](https://vyjava.xyz/dashboard/image/109278aa-961a-4503-bed0-0a9c838dcef2)
|
|
4
4
|
|
|
5
5
|
<hr>
|
|
6
6
|
|
|
7
7
|
[](https://badge.fury.io/py/python3-capsolver)
|
|
8
8
|
[](https://badge.fury.io/py/python3-capsolver)
|
|
9
9
|
[](https://pepy.tech/project/python3-capsolver)
|
|
10
|
+
[](https://andreidrang.github.io/python3-capsolver/)
|
|
10
11
|
|
|
11
12
|
[](https://codeclimate.com/github/AndreiDrang/python3-capsolver/maintainability)
|
|
12
13
|
[](https://www.codacy.com/gh/AndreiDrang/python3-capsolver/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AndreiDrang/python3-capsolver&utm_campaign=Badge_Grade)
|
|
@@ -20,17 +21,10 @@
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
Python 3 library for [Capsolver](https://dashboard.capsolver.com/passport/register?inviteCode=kQTn-tG07Jb1) service API.
|
|
23
|
-
|
|
24
24
|
Tested on UNIX based OS.
|
|
25
25
|
|
|
26
26
|
The library is intended for software developers and is used to work with the [Capsolver](https://dashboard.capsolver.com/passport/register?inviteCode=kQTn-tG07Jb1) service API.
|
|
27
27
|
|
|
28
|
-
***
|
|
29
|
-
|
|
30
|
-
If you have any questions, please send a message to the [Telegram](https://t.me/pythoncaptcha) chat room.
|
|
31
|
-
|
|
32
|
-
Or email python-captcha@pm.me
|
|
33
|
-
|
|
34
28
|
## How to install?
|
|
35
29
|
|
|
36
30
|
We recommend using the latest version of Python. `python3-capsolver` supports Python 3.7+.
|
|
@@ -58,4 +52,10 @@ Check [releases page](https://github.com/AndreiDrang/python3-capsolver/releases)
|
|
|
58
52
|
|
|
59
53
|
### How to get API Key to work with the library
|
|
60
54
|
1. On the page - https://dashboard.capsolver.com/overview/user-center
|
|
61
|
-
2. Find it: 
|
|
55
|
+
2. Find it: [](https://vyjava.xyz/dashboard/image/ae8d4fbf-7451-441d-8984-79b1a7adbe27)
|
|
56
|
+
|
|
57
|
+
### Contacts
|
|
58
|
+
|
|
59
|
+
If you have any questions, please send a message to the [Telegram](https://t.me/pythoncaptcha) chat room.
|
|
60
|
+
|
|
61
|
+
Or email python-captcha@pm.me
|
|
@@ -24,6 +24,7 @@ length_sort = true
|
|
|
24
24
|
[tool.pytest.ini_options]
|
|
25
25
|
minversion = "7.0"
|
|
26
26
|
asyncio_mode = "auto"
|
|
27
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
27
28
|
testpaths = [
|
|
28
29
|
"tests",
|
|
29
30
|
]
|
|
@@ -85,7 +86,7 @@ classifiers = [
|
|
|
85
86
|
dependencies = [
|
|
86
87
|
"requests>=2.21.0",
|
|
87
88
|
"aiohttp>=3.9.2",
|
|
88
|
-
"
|
|
89
|
+
"msgspec>=0.18,<0.20",
|
|
89
90
|
"tenacity>=8,<10"
|
|
90
91
|
]
|
|
91
92
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.1"
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from .core.base import CaptchaParams
|
|
4
|
+
from .core.enum import CaptchaTypeEnm
|
|
5
|
+
|
|
6
|
+
__all__ = ("AwsWaf",)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AwsWaf(CaptchaParams):
|
|
10
|
+
"""
|
|
11
|
+
The class is used to work with Capsolver AwsWaf methods:
|
|
12
|
+
- AntiAwsWafTask
|
|
13
|
+
- AntiAwsWafTaskProxyLess
|
|
14
|
+
- AwsWafClassification
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
api_key: Capsolver API key
|
|
18
|
+
captcha_type: Captcha type name, like ``AntiAwsWafTask`` and etc.
|
|
19
|
+
kwargs: additional params for client, like captcha waiting time
|
|
20
|
+
available keys:
|
|
21
|
+
- sleep_time: int - captcha solution waintig time in sec
|
|
22
|
+
- request_url: str - API address for sending requests,
|
|
23
|
+
else official will be used
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
>>> from python3_capsolver.aws_waf import AwsWaf
|
|
28
|
+
>>> from python3_capsolver.core.captcha_instrument import FileInstrument
|
|
29
|
+
>>> image = FileInstrument().file_processing(captcha_file="waf_captcha.png")
|
|
30
|
+
>>> AwsWaf(api_key="CAP-XXXXX",
|
|
31
|
+
... captcha_type=CaptchaTypeEnm.AwsWafClassification
|
|
32
|
+
... ).captcha_handler(task_payload={
|
|
33
|
+
... "images": [image],
|
|
34
|
+
... "question": "some question",
|
|
35
|
+
... "websiteURL": "https://xxxx.com",
|
|
36
|
+
... })
|
|
37
|
+
{
|
|
38
|
+
"errorId":0,
|
|
39
|
+
"errorCode":"None",
|
|
40
|
+
"errorDescription":"None",
|
|
41
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
42
|
+
"status":"ready",
|
|
43
|
+
"solution":{
|
|
44
|
+
//carcity point
|
|
45
|
+
"box": [
|
|
46
|
+
116.7,
|
|
47
|
+
164.1
|
|
48
|
+
],
|
|
49
|
+
// grid type, objects means the image index that matches the question
|
|
50
|
+
"objects": [0, 1, 3, 4, 6],
|
|
51
|
+
//if question include `bifurcatedzoo`
|
|
52
|
+
"distance": 500
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
>>> import asyncio
|
|
58
|
+
>>> from python3_capsolver.aws_waf import AwsWaf
|
|
59
|
+
>>> from python3_capsolver.core.captcha_instrument import FileInstrument
|
|
60
|
+
>>> image = FileInstrument().file_processing(captcha_file="waf_captcha.png")
|
|
61
|
+
>>> asyncio.run(AwsWaf(api_key="CAP-XXXXX",
|
|
62
|
+
... captcha_type=CaptchaTypeEnm.AwsWafClassification
|
|
63
|
+
... ).aio_captcha_handler(task_payload={
|
|
64
|
+
... "images": [image],
|
|
65
|
+
... "question": "some question",
|
|
66
|
+
... "websiteURL": "https://xxxx.com",
|
|
67
|
+
... }))
|
|
68
|
+
{
|
|
69
|
+
"errorId":0,
|
|
70
|
+
"errorCode":"None",
|
|
71
|
+
"errorDescription":"None",
|
|
72
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
73
|
+
"status":"ready",
|
|
74
|
+
"solution":{
|
|
75
|
+
//carcity point
|
|
76
|
+
"box": [
|
|
77
|
+
116.7,
|
|
78
|
+
164.1
|
|
79
|
+
],
|
|
80
|
+
// grid type, objects means the image index that matches the question
|
|
81
|
+
"objects": [0, 1, 3, 4, 6],
|
|
82
|
+
//if question include `bifurcatedzoo`
|
|
83
|
+
"distance": 500
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
>>> from python3_capsolver.aws_waf import AwsWaf
|
|
88
|
+
>>> from python3_capsolver.core.captcha_instrument import FileInstrument
|
|
89
|
+
>>> image = FileInstrument().file_processing(captcha_file="waf_captcha.png")
|
|
90
|
+
>>> AwsWaf(api_key="CAP-XXXXX",
|
|
91
|
+
... captcha_type=CaptchaTypeEnm.AntiAwsWafTaskProxyLess
|
|
92
|
+
... ).captcha_handler(task_payload={
|
|
93
|
+
... "websiteURL": "https://xxxxxx/latest",
|
|
94
|
+
... "awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
|
|
95
|
+
... "awsChallengeJS": "https://xxxxx/challenge.js",
|
|
96
|
+
... })
|
|
97
|
+
{
|
|
98
|
+
"errorId":0,
|
|
99
|
+
"errorCode":"None",
|
|
100
|
+
"errorDescription":"None",
|
|
101
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
102
|
+
"status":"ready",
|
|
103
|
+
"solution":{
|
|
104
|
+
"cookie": "223d1f60-xxxxxxxx"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
>>> from python3_capsolver.aws_waf import AwsWaf
|
|
109
|
+
>>> from python3_capsolver.core.captcha_instrument import FileInstrument
|
|
110
|
+
>>> image = FileInstrument().file_processing(captcha_file="waf_captcha.png")
|
|
111
|
+
>>> AwsWaf(api_key="CAP-XXXXX",
|
|
112
|
+
... captcha_type=CaptchaTypeEnm.AntiAwsWafTask
|
|
113
|
+
... ).captcha_handler(task_payload={
|
|
114
|
+
... "websiteURL": "https://xxxxxx/latest",
|
|
115
|
+
... "awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
|
|
116
|
+
... "awsChallengeJS": "https://xxxxx/challenge.js",
|
|
117
|
+
... "proxy": "ip:port:user:pass"
|
|
118
|
+
... })
|
|
119
|
+
{
|
|
120
|
+
"errorId":0,
|
|
121
|
+
"errorCode":"None",
|
|
122
|
+
"errorDescription":"None",
|
|
123
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
124
|
+
"status":"ready",
|
|
125
|
+
"solution":{
|
|
126
|
+
"cookie": "223d1f60-xxxxxxxx"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Notes:
|
|
131
|
+
https://docs.capsolver.com/en/guide/captcha/awsWaf/
|
|
132
|
+
|
|
133
|
+
https://docs.capsolver.com/en/guide/recognition/AwsWafClassification/
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
def __init__(self, api_key: str, captcha_type: Union[CaptchaTypeEnm, str], **kwargs):
|
|
137
|
+
|
|
138
|
+
super().__init__(api_key=api_key, captcha_type=captcha_type, **kwargs)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from .core.base import CaptchaParams
|
|
4
|
+
from .core.enum import CaptchaTypeEnm
|
|
5
|
+
|
|
6
|
+
__all__ = ("Cloudflare",)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Cloudflare(CaptchaParams):
|
|
10
|
+
"""
|
|
11
|
+
The class is used to work with Capsolver AntiTurnstileTaskProxyLess captcha solving method
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
api_key: Capsolver API key
|
|
15
|
+
captcha_type: Captcha type name, like ``AntiTurnstileTaskProxyLess`` and etc.
|
|
16
|
+
kwargs: additional params for client, like captcha waiting time
|
|
17
|
+
available keys:
|
|
18
|
+
- sleep_time: int - captcha solution waintig time in sec
|
|
19
|
+
- request_url: str - API address for sending requests,
|
|
20
|
+
else official will be used
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
>>> from python3_capsolver.cloudflare import Cloudflare
|
|
24
|
+
>>> from python3_capsolver.core.enum import CaptchaTypeEnm
|
|
25
|
+
>>> Cloudflare(api_key="CAI-12345....",
|
|
26
|
+
... captcha_type=CaptchaTypeEnm.AntiTurnstileTaskProxyLess)
|
|
27
|
+
... .captcha_handler(task_payload={
|
|
28
|
+
... "websiteKey": "0x4XXXXXXXXXXXXXXXXX",
|
|
29
|
+
... "metadata": {
|
|
30
|
+
... "action": "login",
|
|
31
|
+
... "cdata": "0000-1111-2222-3333-example-cdata"
|
|
32
|
+
... }
|
|
33
|
+
... })
|
|
34
|
+
{
|
|
35
|
+
"errorId":0,
|
|
36
|
+
"errorCode":"None",
|
|
37
|
+
"errorDescription":"None",
|
|
38
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
39
|
+
"status":"ready",
|
|
40
|
+
"solution":{
|
|
41
|
+
"token": "0.mF74FV8wEufAWxxxx",
|
|
42
|
+
"type": "turnstile",
|
|
43
|
+
"userAgent": "Mozilla/5.0 xxxx"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
>>> from python3_capsolver.cloudflare import Cloudflare
|
|
48
|
+
>>> from python3_capsolver.core.enum import CaptchaTypeEnm
|
|
49
|
+
>>> Cloudflare(api_key="CAI-12345....",
|
|
50
|
+
... captcha_type=CaptchaTypeEnm.AntiCloudflareTask)
|
|
51
|
+
... .captcha_handler(task_payload={
|
|
52
|
+
... "websiteURL": "https://www.yourwebsite.com",
|
|
53
|
+
... "proxy": "ip:port:user:pass",
|
|
54
|
+
... })
|
|
55
|
+
{
|
|
56
|
+
"errorId":0,
|
|
57
|
+
"errorCode":"None",
|
|
58
|
+
"errorDescription":"None",
|
|
59
|
+
"taskId":"db0a3153-621d-4f5e-8554-a1c032597ee7",
|
|
60
|
+
"status":"ready",
|
|
61
|
+
"solution":{
|
|
62
|
+
"cookies": "cf_clearance=_VPxxxx",
|
|
63
|
+
"headers": {
|
|
64
|
+
"sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
|
|
65
|
+
"sec-ch-ua-platform": "\"Windows\"",
|
|
66
|
+
"accept": "text/html,axxxx",
|
|
67
|
+
"User-Agent": "Mozilla/5.0xxxx",
|
|
68
|
+
"sec-ch-ua-mobile": "?0",
|
|
69
|
+
"sec-fetch-user": "?1",
|
|
70
|
+
"referer": "https://www.yourwebsite.com",
|
|
71
|
+
"Sec-Fetch-Dest": "document",
|
|
72
|
+
"Sec-Fetch-Mode": "navigate",
|
|
73
|
+
"Sec-Fetch-Site": "same-origin",
|
|
74
|
+
"accept-language": "en",
|
|
75
|
+
},
|
|
76
|
+
"page_url": "https://www.yourwebsite.com",
|
|
77
|
+
"proxy": "your proxyxxxx",
|
|
78
|
+
"token": "_VPCTZXP5bhinxxxx"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
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
|
+
|
|
118
|
+
Notes:
|
|
119
|
+
https://docs.capsolver.com/en/guide/captcha/cloudflare_turnstile/
|
|
120
|
+
|
|
121
|
+
https://docs.capsolver.com/en/guide/captcha/cloudflare_challenge/
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
def __init__(
|
|
125
|
+
self,
|
|
126
|
+
api_key: str,
|
|
127
|
+
captcha_type: Union[CaptchaTypeEnm, str] = CaptchaTypeEnm.AntiTurnstileTaskProxyLess,
|
|
128
|
+
**kwargs,
|
|
129
|
+
):
|
|
130
|
+
|
|
131
|
+
super().__init__(api_key=api_key, captcha_type=captcha_type, **kwargs)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from .core.base import CaptchaParams
|
|
2
|
+
from .core.enum import CaptchaTypeEnm
|
|
3
|
+
from .core.const import GET_BALANCE_POSTFIX
|
|
4
|
+
from .core.aio_captcha_instrument import AIOCaptchaInstrument
|
|
5
|
+
from .core.sio_captcha_instrument import SIOCaptchaInstrument
|
|
6
|
+
|
|
7
|
+
__all__ = ("Control",)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Control(CaptchaParams):
|
|
11
|
+
"""
|
|
12
|
+
The class is used to work with Capsolver control methods.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
api_key: Capsolver API key
|
|
16
|
+
|
|
17
|
+
Notes:
|
|
18
|
+
https://docs.capsolver.com/en/guide/api-getbalance/
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
api_key: str,
|
|
24
|
+
):
|
|
25
|
+
super().__init__(api_key=api_key, captcha_type=CaptchaTypeEnm.Control)
|
|
26
|
+
|
|
27
|
+
def get_balance(self) -> dict:
|
|
28
|
+
"""
|
|
29
|
+
Synchronous method to view the balance
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
>>> from python3_capsolver.control import Control
|
|
33
|
+
>>> Control(api_key="CAI-1324...").get_balance()
|
|
34
|
+
{'balance': 48.6361, 'errorId': 0, 'packages': []}
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
Dict with full server response
|
|
38
|
+
|
|
39
|
+
Notes:
|
|
40
|
+
Check class docstring for more info
|
|
41
|
+
"""
|
|
42
|
+
self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
|
|
43
|
+
return self._captcha_handling_instrument.send_post_request(
|
|
44
|
+
session=self._captcha_handling_instrument.session,
|
|
45
|
+
url_postfix=GET_BALANCE_POSTFIX,
|
|
46
|
+
payload={"clientKey": self.create_task_payload.clientKey},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
async def aio_get_balance(self) -> dict:
|
|
50
|
+
"""
|
|
51
|
+
Asynchronous method to view the balance
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
>>> import asyncio
|
|
55
|
+
>>> from python3_capsolver.control import Control
|
|
56
|
+
>>> asyncio.run(Control(api_key="CAI-1324...").aio_get_balance())
|
|
57
|
+
{'balance': 48.6361, 'errorId': 0, 'packages': []}
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Dict with full server response
|
|
61
|
+
|
|
62
|
+
Notes:
|
|
63
|
+
Check class docstring for more info
|
|
64
|
+
"""
|
|
65
|
+
return await AIOCaptchaInstrument.send_post_request(
|
|
66
|
+
url_postfix=GET_BALANCE_POSTFIX,
|
|
67
|
+
payload={"clientKey": self.create_task_payload.clientKey},
|
|
68
|
+
)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from urllib import parse
|
|
5
|
+
|
|
6
|
+
import aiohttp
|
|
7
|
+
|
|
8
|
+
from .enum import ResponseStatusEnm, EndpointPostfixEnm
|
|
9
|
+
from .const import REQUEST_URL, VALID_STATUS_CODES, GET_BALANCE_POSTFIX
|
|
10
|
+
from .utils import attempts_generator
|
|
11
|
+
from .serializer import CaptchaResponseSer
|
|
12
|
+
from .captcha_instrument import CaptchaInstrument
|
|
13
|
+
|
|
14
|
+
__all__ = ("AIOCaptchaInstrument",)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AIOCaptchaInstrument(CaptchaInstrument):
|
|
18
|
+
"""
|
|
19
|
+
Instrument for working with async captcha
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, captcha_params: "CaptchaParams"):
|
|
23
|
+
super().__init__()
|
|
24
|
+
self.captcha_params = captcha_params
|
|
25
|
+
self.created_task_data = CaptchaResponseSer
|
|
26
|
+
|
|
27
|
+
async def processing_captcha(self) -> dict:
|
|
28
|
+
self.captcha_params.create_task_payload.task = self.captcha_params.task_params
|
|
29
|
+
self.created_task_data = CaptchaResponseSer(**await self.__create_task())
|
|
30
|
+
|
|
31
|
+
# if task created and already ready - return result
|
|
32
|
+
if self.created_task_data.errorId == 0 and self.created_task_data.status == ResponseStatusEnm.Processing.value:
|
|
33
|
+
return (await self.__get_result()).to_dict()
|
|
34
|
+
elif self.created_task_data.errorId != 0:
|
|
35
|
+
self.created_task_data.status = ResponseStatusEnm.Failed
|
|
36
|
+
|
|
37
|
+
return self.created_task_data.to_dict()
|
|
38
|
+
|
|
39
|
+
async def __create_task(self, url_postfix: str = EndpointPostfixEnm.CREATE_TASK.value) -> dict:
|
|
40
|
+
"""
|
|
41
|
+
Function send the ASYNC request to service and wait for result
|
|
42
|
+
"""
|
|
43
|
+
async with aiohttp.ClientSession() as session:
|
|
44
|
+
try:
|
|
45
|
+
async with session.post(
|
|
46
|
+
parse.urljoin(self.captcha_params.request_url, url_postfix),
|
|
47
|
+
json=self.captcha_params.create_task_payload.to_dict(),
|
|
48
|
+
) as resp:
|
|
49
|
+
if resp.status in VALID_STATUS_CODES:
|
|
50
|
+
return await resp.json()
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError(resp.reason)
|
|
53
|
+
except Exception as error:
|
|
54
|
+
logging.exception(error)
|
|
55
|
+
raise
|
|
56
|
+
|
|
57
|
+
async def __get_result(self, url_postfix: str = EndpointPostfixEnm.GET_TASK_RESULT.value) -> CaptchaResponseSer:
|
|
58
|
+
"""
|
|
59
|
+
Function send the ASYNC request to service and wait for result
|
|
60
|
+
"""
|
|
61
|
+
# initial waiting
|
|
62
|
+
await asyncio.sleep(self.captcha_params.sleep_time)
|
|
63
|
+
|
|
64
|
+
self.captcha_params.get_result_params.taskId = self.created_task_data.taskId
|
|
65
|
+
attempts = attempts_generator()
|
|
66
|
+
async with aiohttp.ClientSession() as session:
|
|
67
|
+
for _ in attempts:
|
|
68
|
+
try:
|
|
69
|
+
async with session.post(
|
|
70
|
+
parse.urljoin(self.captcha_params.request_url, url_postfix),
|
|
71
|
+
json=self.captcha_params.get_result_params.to_dict(),
|
|
72
|
+
) as resp:
|
|
73
|
+
if resp.status in VALID_STATUS_CODES:
|
|
74
|
+
result_data = CaptchaResponseSer(**await resp.json())
|
|
75
|
+
if result_data.status in (ResponseStatusEnm.Ready, ResponseStatusEnm.Failed):
|
|
76
|
+
# if captcha ready\failed or have unknown status - return exist data
|
|
77
|
+
return result_data
|
|
78
|
+
else:
|
|
79
|
+
raise ValueError(resp.reason)
|
|
80
|
+
except Exception as error:
|
|
81
|
+
logging.exception(error)
|
|
82
|
+
raise
|
|
83
|
+
|
|
84
|
+
# if captcha just created or in processing now - wait
|
|
85
|
+
await asyncio.sleep(self.captcha_params.sleep_time)
|
|
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
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
async def send_post_request(payload: Optional[dict] = None, url_postfix: str = GET_BALANCE_POSTFIX) -> dict:
|
|
96
|
+
"""
|
|
97
|
+
Function send ASYNC request to service and wait for result
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
async with aiohttp.ClientSession() as session:
|
|
101
|
+
try:
|
|
102
|
+
async with session.post(parse.urljoin(REQUEST_URL, url_postfix), json=payload) as resp:
|
|
103
|
+
if resp.status == 200:
|
|
104
|
+
return await resp.json()
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError(resp.status)
|
|
107
|
+
except Exception as error:
|
|
108
|
+
logging.exception(error)
|
|
109
|
+
raise
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
from python3_capsolver.core.enum import CaptchaTypeEnm
|
|
4
|
+
from python3_capsolver.core.serializer import TaskSer
|
|
5
|
+
|
|
6
|
+
from .const import REQUEST_URL
|
|
7
|
+
from .serializer import RequestCreateTaskSer, RequestGetTaskResultSer
|
|
8
|
+
from .context_instr import AIOContextManager, SIOContextManager
|
|
9
|
+
from .captcha_instrument import CaptchaInstrument
|
|
10
|
+
from .aio_captcha_instrument import AIOCaptchaInstrument
|
|
11
|
+
from .sio_captcha_instrument import SIOCaptchaInstrument
|
|
12
|
+
|
|
13
|
+
__all__ = ("CaptchaParams",)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CaptchaParams(SIOContextManager, AIOContextManager):
|
|
17
|
+
"""
|
|
18
|
+
Basic Captcha solving class
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
api_key: Capsolver API key
|
|
22
|
+
captcha_type: Captcha type name, like `ReCaptchaV2Task` and etc.
|
|
23
|
+
sleep_time: The waiting time between requests to get the result of the Captcha
|
|
24
|
+
request_url: API address for sending requests
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
api_key: str,
|
|
30
|
+
captcha_type: CaptchaTypeEnm,
|
|
31
|
+
sleep_time: int = 5,
|
|
32
|
+
request_url: str = REQUEST_URL,
|
|
33
|
+
):
|
|
34
|
+
# assign args to validator
|
|
35
|
+
self.create_task_payload = RequestCreateTaskSer(clientKey=api_key)
|
|
36
|
+
# `task` body for task creation payload
|
|
37
|
+
self.task_params = TaskSer(type=captcha_type.value).to_dict()
|
|
38
|
+
# prepare `get task result` payload
|
|
39
|
+
self.get_result_params = RequestGetTaskResultSer(clientKey=api_key)
|
|
40
|
+
self.request_url = request_url
|
|
41
|
+
self._captcha_handling_instrument = CaptchaInstrument()
|
|
42
|
+
self.sleep_time = sleep_time
|
|
43
|
+
|
|
44
|
+
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
|
|
45
|
+
"""
|
|
46
|
+
Synchronous method for captcha solving
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
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 ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
|
|
52
|
+
more info in service docs
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Dict with full server response
|
|
56
|
+
|
|
57
|
+
Notes:
|
|
58
|
+
Check class docstirng for more info
|
|
59
|
+
"""
|
|
60
|
+
self.task_params.update(task_payload)
|
|
61
|
+
self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
|
|
62
|
+
return self._captcha_handling_instrument.processing_captcha()
|
|
63
|
+
|
|
64
|
+
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
|
|
65
|
+
"""
|
|
66
|
+
Asynchronous method for captcha solving
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
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 ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
|
|
72
|
+
more info in service docs
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Dict with full server response
|
|
76
|
+
|
|
77
|
+
Notes:
|
|
78
|
+
Check class docstirng for more info
|
|
79
|
+
"""
|
|
80
|
+
self.task_params.update(task_payload)
|
|
81
|
+
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
|
|
82
|
+
return await self._captcha_handling_instrument.processing_captcha()
|