Skip to content

Commit c97d383

Browse files
authored
Merge pull request #139 from AndreiDrang/main
v1.0.1
2 parents 643ee10 + 6bb1e77 commit c97d383

File tree

17 files changed

+122
-33
lines changed

17 files changed

+122
-33
lines changed

docs/modules/aws-waf/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.aws_waf.AwsWaf
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/cloudflare/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.cloudflare.Cloudflare
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/datadome/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.datadome_slider.DatadomeSlider
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/friendly/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.friendly_captcha.FriendlyCaptcha
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/gee-test/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.gee_test.GeeTest
12-
:members:
12+
:members:
13+
:inherited-members:
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ImageToText
2-
=============
2+
===========
33

44
To import this module:
55

@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.image_to_text.ImageToText
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/mt-captcha/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.mt_captcha.MtCaptcha
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/re-captcha/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.recaptcha.ReCaptcha
12-
:members:
12+
:members:
13+
:inherited-members:

docs/modules/yandex/example.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ To import this module:
99
1010
1111
.. autoclass:: python3_capsolver.yandex.YandexCaptcha
12-
:members:
12+
:members:
13+
:inherited-members:

src/python3_capsolver/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0a"
1+
__version__ = "1.0.1"

src/python3_capsolver/core/base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict
1+
from typing import Any, Dict
22

33
from python3_capsolver.core.enum import CaptchaTypeEnm
44
from python3_capsolver.core.serializer import TaskSer
@@ -41,15 +41,15 @@ def __init__(
4141
self._captcha_handling_instrument = CaptchaInstrument()
4242
self.sleep_time = sleep_time
4343

44-
def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
44+
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
4545
"""
4646
Synchronous method for captcha solving
4747
4848
Args:
4949
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-
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
5353
5454
Returns:
5555
Dict with full server response
@@ -61,14 +61,15 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
6161
self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
6262
return self._captcha_handling_instrument.processing_captcha()
6363

64-
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
64+
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
6565
"""
6666
Asynchronous method for captcha solving
6767
6868
Args:
6969
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
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
7273
7374
Returns:
7475
Dict with full server response

src/python3_capsolver/core/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class MyBaseModel(Struct):
13-
def to_dict(self) -> Dict[str, str]:
13+
def to_dict(self) -> Dict[str, Any]:
1414
result = {}
1515
for f in self.__struct_fields__:
1616
if isinstance(getattr(self, f), Enum):

src/python3_capsolver/image_to_text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict
1+
from typing import Any, Dict
22

33
from .core.base import CaptchaParams
44
from .core.enum import CaptchaTypeEnm
@@ -88,7 +88,7 @@ def __init__(self, api_key: str, **kwargs):
8888

8989
super().__init__(api_key=api_key, captcha_type=CaptchaTypeEnm.ImageToTextTask, **kwargs)
9090

91-
def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
91+
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
9292
"""
9393
Synchronous method for captcha solving
9494
@@ -104,7 +104,7 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
104104
task_payload.pop("type", None)
105105
return super().captcha_handler(task_payload=task_payload)
106106

107-
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
107+
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
108108
"""
109109
Asynchronous method for captcha solving
110110

src/python3_capsolver/vision_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict
1+
from typing import Any, Dict
22

33
from .core.base import CaptchaParams
44
from .core.enum import CaptchaTypeEnm
@@ -69,7 +69,7 @@ class VisionEngine(CaptchaParams):
6969
def __init__(self, api_key: str, **kwargs):
7070
super().__init__(api_key=api_key, captcha_type=CaptchaTypeEnm.VisionEngine, **kwargs)
7171

72-
def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
72+
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
7373
"""
7474
Synchronous method for captcha solving
7575
@@ -85,7 +85,7 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
8585
task_payload.pop("type", None)
8686
return super().captcha_handler(task_payload=task_payload)
8787

88-
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
88+
async def aio_captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
8989
"""
9090
Asynchronous method for captcha solving
9191

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ def get_random_string(length: int = 36) -> str:
4848
result_str = "".join(random.choice(letters) for _ in range(length))
4949
return result_str
5050

51-
def read_image(self) -> bytes:
52-
with open(self.image_captcha_path_example, "rb") as img_file:
51+
@staticmethod
52+
def read_image(file_path: str = image_captcha_path_example) -> bytes:
53+
with open(file_path, "rb") as img_file:
5354
return img_file.read()
5455

55-
def read_image_as_str(self) -> str:
56-
return base64.b64encode(self.read_image()).decode("utf-8")
56+
def read_image_as_str(self, file_path: str = image_captcha_path_example) -> str:
57+
return base64.b64encode(self.read_image(file_path=file_path)).decode("utf-8")
128 KB
Loading

tests/test_aws_waf.py

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from tests.conftest import BaseTest
44
from python3_capsolver.aws_waf import AwsWaf
5-
from python3_capsolver.core.enum import CaptchaTypeEnm
5+
from python3_capsolver.core.enum import CaptchaTypeEnm, ResponseStatusEnm
66

77

88
class TestAwsWafBase(BaseTest):
@@ -24,7 +24,7 @@ def test_api_key_err(self, captcha_type):
2424
task_payload={"some": "data"}
2525
)
2626
assert result["errorId"] == 1
27-
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
27+
assert result["errorCode"] in ("ERROR_INVALID_TASK_DATA", "ERROR_KEY_DENIED_ACCESS")
2828
assert result["solution"] is None
2929

3030
@pytest.mark.parametrize("captcha_type", captcha_types)
@@ -33,5 +33,83 @@ async def test_aio_api_key_err(self, captcha_type):
3333
task_payload={"some": "data"}
3434
)
3535
assert result["errorId"] == 1
36-
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
36+
assert result["errorCode"] in ("ERROR_INVALID_TASK_DATA", "ERROR_KEY_DENIED_ACCESS")
37+
assert result["solution"] is None
38+
39+
40+
class TestAwsWafClassification(BaseTest):
41+
toycarcity_image = "tests/files/aws_waf_class_toycarcity.png"
42+
43+
def test_success(self):
44+
result = AwsWaf(api_key=self.API_KEY, captcha_type=CaptchaTypeEnm.AwsWafClassification).captcha_handler(
45+
task_payload={
46+
"images": [self.read_image_as_str(file_path=self.toycarcity_image)],
47+
"question": "aws:toycarcity:carcity",
48+
}
49+
)
50+
assert result["errorId"] == 0
51+
assert result["errorCode"] is None
52+
assert isinstance(result["solution"], dict)
53+
assert result["status"] == ResponseStatusEnm.Ready.value
54+
assert result["taskId"] is not ""
55+
56+
def test_api_key_err(self):
57+
result = AwsWaf(
58+
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AwsWafClassification
59+
).captcha_handler(
60+
task_payload={
61+
"images": [self.read_image_as_str()],
62+
"question": "aws:toycarcity:carcity",
63+
}
64+
)
65+
assert result["errorId"] == 1
66+
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
67+
assert result["solution"] is None
68+
69+
async def test_aio_api_key_err(self):
70+
result = await AwsWaf(
71+
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AwsWafClassification
72+
).aio_captcha_handler(
73+
task_payload={
74+
"images": [self.read_image_as_str()],
75+
"question": "aws:toycarcity:carcity",
76+
}
77+
)
78+
assert result["errorId"] == 1
79+
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
80+
assert result["solution"] is None
81+
82+
83+
class TestAntiAwsWafTaskProxyLess(BaseTest):
84+
85+
def test_api_key_err(self):
86+
result = AwsWaf(
87+
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AntiAwsWafTaskProxyLess
88+
).captcha_handler(
89+
task_payload={
90+
"websiteURL": "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
91+
"awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
92+
"awsIv": "CgAAFDIlckAAAAid",
93+
"awsContext": "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=",
94+
"awsChallengeJS": "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
95+
}
96+
)
97+
assert result["errorId"] == 1
98+
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
99+
assert result["solution"] is None
100+
101+
async def test_aio_api_key_err(self):
102+
result = await AwsWaf(
103+
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AntiAwsWafTaskProxyLess
104+
).aio_captcha_handler(
105+
task_payload={
106+
"websiteURL": "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
107+
"awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
108+
"awsIv": "CgAAFDIlckAAAAid",
109+
"awsContext": "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=",
110+
"awsChallengeJS": "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
111+
}
112+
)
113+
assert result["errorId"] == 1
114+
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
37115
assert result["solution"] is None

0 commit comments

Comments
 (0)