Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/modules/aws-waf/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.aws_waf.AwsWaf
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/cloudflare/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.cloudflare.Cloudflare
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/datadome/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.datadome_slider.DatadomeSlider
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/friendly/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.friendly_captcha.FriendlyCaptcha
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/gee-test/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.gee_test.GeeTest
:members:
:members:
:inherited-members:
5 changes: 3 additions & 2 deletions docs/modules/image-to-text/example.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ImageToText
=============
===========

To import this module:

Expand All @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.image_to_text.ImageToText
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/mt-captcha/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.mt_captcha.MtCaptcha
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/re-captcha/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.recaptcha.ReCaptcha
:members:
:members:
:inherited-members:
3 changes: 2 additions & 1 deletion docs/modules/yandex/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ To import this module:


.. autoclass:: python3_capsolver.yandex.YandexCaptcha
:members:
:members:
:inherited-members:
2 changes: 1 addition & 1 deletion src/python3_capsolver/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0a"
__version__ = "1.0.1"
17 changes: 9 additions & 8 deletions src/python3_capsolver/core/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Any, Dict

from python3_capsolver.core.enum import CaptchaTypeEnm
from python3_capsolver.core.serializer import TaskSer
Expand Down Expand Up @@ -41,15 +41,15 @@ def __init__(
self._captcha_handling_instrument = CaptchaInstrument()
self.sleep_time = sleep_time

def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
"""
Synchronous method for captcha solving

Args:
task_payload: Some additional parameters that will be used in creating the task
and will be passed to the payload under ``task`` key.
Like ``proxyLogin``, ``proxyPassword`` and etc. - more info in service docs

and will be passed to the payload under ``task`` key.
Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
more info in service docs

Returns:
Dict with full server response
Expand All @@ -61,14 +61,15 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
self._captcha_handling_instrument = SIOCaptchaInstrument(captcha_params=self)
return self._captcha_handling_instrument.processing_captcha()

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

Args:
task_payload: Some additional parameters that will be used in creating the task
and will be passed to the payload under ``task`` key.
Like ``proxyLogin``, ``proxyPassword`` and etc. - more info in service docs
and will be passed to the payload under ``task`` key.
Like ``websiteURL``, ``image``, ``proxyPassword``, ``websiteKey`` and etc.
more info in service docs

Returns:
Dict with full server response
Expand Down
2 changes: 1 addition & 1 deletion src/python3_capsolver/core/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class MyBaseModel(Struct):
def to_dict(self) -> Dict[str, str]:
def to_dict(self) -> Dict[str, Any]:
result = {}
for f in self.__struct_fields__:
if isinstance(getattr(self, f), Enum):
Expand Down
6 changes: 3 additions & 3 deletions src/python3_capsolver/image_to_text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Any, Dict

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

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

def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
"""
Synchronous method for captcha solving

Expand All @@ -104,7 +104,7 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
task_payload.pop("type", None)
return super().captcha_handler(task_payload=task_payload)

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

Expand Down
6 changes: 3 additions & 3 deletions src/python3_capsolver/vision_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Any, Dict

from .core.base import CaptchaParams
from .core.enum import CaptchaTypeEnm
Expand Down Expand Up @@ -69,7 +69,7 @@ class VisionEngine(CaptchaParams):
def __init__(self, api_key: str, **kwargs):
super().__init__(api_key=api_key, captcha_type=CaptchaTypeEnm.VisionEngine, **kwargs)

def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
def captcha_handler(self, task_payload: Dict) -> Dict[str, Any]:
"""
Synchronous method for captcha solving

Expand All @@ -85,7 +85,7 @@ def captcha_handler(self, task_payload: Dict) -> Dict[str, str]:
task_payload.pop("type", None)
return super().captcha_handler(task_payload=task_payload)

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

Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def get_random_string(length: int = 36) -> str:
result_str = "".join(random.choice(letters) for _ in range(length))
return result_str

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

def read_image_as_str(self) -> str:
return base64.b64encode(self.read_image()).decode("utf-8")
def read_image_as_str(self, file_path: str = image_captcha_path_example) -> str:
return base64.b64encode(self.read_image(file_path=file_path)).decode("utf-8")
Binary file added tests/files/aws_waf_class_toycarcity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 81 additions & 3 deletions tests/test_aws_waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from tests.conftest import BaseTest
from python3_capsolver.aws_waf import AwsWaf
from python3_capsolver.core.enum import CaptchaTypeEnm
from python3_capsolver.core.enum import CaptchaTypeEnm, ResponseStatusEnm


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

@pytest.mark.parametrize("captcha_type", captcha_types)
Expand All @@ -33,5 +33,83 @@ async def test_aio_api_key_err(self, captcha_type):
task_payload={"some": "data"}
)
assert result["errorId"] == 1
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
assert result["errorCode"] in ("ERROR_INVALID_TASK_DATA", "ERROR_KEY_DENIED_ACCESS")
assert result["solution"] is None


class TestAwsWafClassification(BaseTest):
toycarcity_image = "tests/files/aws_waf_class_toycarcity.png"

def test_success(self):
result = AwsWaf(api_key=self.API_KEY, captcha_type=CaptchaTypeEnm.AwsWafClassification).captcha_handler(
task_payload={
"images": [self.read_image_as_str(file_path=self.toycarcity_image)],
"question": "aws:toycarcity:carcity",
}
)
assert result["errorId"] == 0
assert result["errorCode"] is None
assert isinstance(result["solution"], dict)
assert result["status"] == ResponseStatusEnm.Ready.value
assert result["taskId"] is not ""

def test_api_key_err(self):
result = AwsWaf(
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AwsWafClassification
).captcha_handler(
task_payload={
"images": [self.read_image_as_str()],
"question": "aws:toycarcity:carcity",
}
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
assert result["solution"] is None

async def test_aio_api_key_err(self):
result = await AwsWaf(
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AwsWafClassification
).aio_captcha_handler(
task_payload={
"images": [self.read_image_as_str()],
"question": "aws:toycarcity:carcity",
}
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
assert result["solution"] is None


class TestAntiAwsWafTaskProxyLess(BaseTest):

def test_api_key_err(self):
result = AwsWaf(
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AntiAwsWafTaskProxyLess
).captcha_handler(
task_payload={
"websiteURL": "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
"awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
"awsIv": "CgAAFDIlckAAAAid",
"awsContext": "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=",
"awsChallengeJS": "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
}
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
assert result["solution"] is None

async def test_aio_api_key_err(self):
result = await AwsWaf(
api_key=self.get_random_string(36), captcha_type=CaptchaTypeEnm.AntiAwsWafTaskProxyLess
).aio_captcha_handler(
task_payload={
"websiteURL": "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest",
"awsKey": "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==",
"awsIv": "CgAAFDIlckAAAAid",
"awsContext": "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=",
"awsChallengeJS": "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
}
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
assert result["solution"] is None
Loading