|
1 | | -from typing import Union |
| 1 | +from typing import Union, Optional |
2 | 2 |
|
3 | | -from python3_capsolver.core.base import BaseCaptcha |
4 | | -from python3_capsolver.core.enum import AntiAwsWafTaskTypeEnm |
5 | | -from python3_capsolver.core.serializer import CaptchaResponseSer, WebsiteDataOptionsSer |
| 3 | +from .core.base import CaptchaParams |
| 4 | +from .core.enum import AntiAwsWafTaskTypeEnm |
6 | 5 |
|
| 6 | +__all__ = ("AwsWaf",) |
7 | 7 |
|
8 | | -class AwsWaf(BaseCaptcha): |
9 | | - """ |
10 | | - The class is used to work with Capsolver AwsWaf methods. |
11 | 8 |
|
12 | | - Args: |
13 | | - api_key: Capsolver API key |
14 | | - captcha_type: Captcha type name, like ``AntiAwsWafTask`` and etc. |
15 | | - websiteURL: Address of a webpage with AwsWaf |
16 | | -
|
17 | | - Examples: |
18 | | - >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
19 | | - ... captcha_type='AntiAwsWafTaskProxyLess', |
20 | | - ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
21 | | - ... ).captcha_handler() |
22 | | - CaptchaResponseSer(errorId=0, |
23 | | - errorCode=None, |
24 | | - errorDescription=None, |
25 | | - taskId='73bdcd28-6c77-4414-8....', |
26 | | - status=<ResponseStatusEnm.Ready: 'ready'>, |
27 | | - solution={'cookie': '44795sds...'} |
28 | | - ) |
29 | | -
|
30 | | - >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
31 | | - ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTaskProxyLess, |
32 | | - ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
33 | | - ... ).captcha_handler() |
34 | | - CaptchaResponseSer(errorId=0, |
35 | | - errorCode=None, |
36 | | - errorDescription=None, |
37 | | - taskId='73bdcd28-6c77-4414-8....', |
38 | | - status=<ResponseStatusEnm.Ready: 'ready'>, |
39 | | - solution={'cookie': '44795sds...'} |
40 | | - ) |
41 | | -
|
42 | | - >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
43 | | - ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTask, |
44 | | - ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
45 | | - ... proxy="socks5:192.191.100.10:4780:user:pwd", |
46 | | - ... awsKey="some key" |
47 | | - ... ).captcha_handler() |
48 | | - CaptchaResponseSer(errorId=0, |
49 | | - errorCode=None, |
50 | | - errorDescription=None, |
51 | | - taskId="87f149f4-1c....", |
52 | | - status=<ResponseStatusEnm.Ready: 'ready'>, |
53 | | - solution={'cookie': '44795sds...'} |
54 | | - ) |
55 | | -
|
56 | | - >>> await AwsWaf(api_key="CAI-BA9650D2B9C2786B21120D512702E010", |
57 | | - ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTaskProxyLess, |
58 | | - ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
59 | | - ... ).aio_captcha_handler() |
60 | | - CaptchaResponseSer(errorId=0, |
61 | | - errorCode=None, |
62 | | - errorDescription=None, |
63 | | - taskId='73bdcd28-6c77-4414-8....', |
64 | | - status=<ResponseStatusEnm.Ready: 'ready'>, |
65 | | - solution={'cookie': '44795sds...'} |
66 | | - ) |
| 9 | +class AwsWaf(CaptchaParams): |
| 10 | + def __init__( |
| 11 | + self, |
| 12 | + api_key: str, |
| 13 | + captcha_type: Union[AntiAwsWafTaskTypeEnm, str], |
| 14 | + websiteURL: str, |
| 15 | + sleep_time: Optional[int] = 10, |
| 16 | + **additional_params, |
| 17 | + ): |
| 18 | + """ |
| 19 | + The class is used to work with Capsolver AwsWaf methods. |
| 20 | +
|
| 21 | + Args: |
| 22 | + api_key: Capsolver API key |
| 23 | + captcha_type: Captcha type name, like ``AntiAwsWafTask`` and etc. |
| 24 | + websiteURL: Address of a webpage with AwsWaf |
| 25 | + additional_params: Some additional parameters that will be used in creating the task |
| 26 | + and will be passed to the payload under ``task`` key. |
| 27 | + Like ``proxyLogin``, ``proxyPassword`` and etc. - more info in service docs |
| 28 | +
|
| 29 | +
|
| 30 | + Examples: |
| 31 | + >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
| 32 | + ... captcha_type='AntiAwsWafTaskProxyLess', |
| 33 | + ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
| 34 | + ... ).captcha_handler() |
| 35 | + CaptchaResponseSer(errorId=0, |
| 36 | + errorCode=None, |
| 37 | + errorDescription=None, |
| 38 | + taskId='73bdcd28-6c77-4414-8....', |
| 39 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 40 | + solution={'cookie': '44795sds...'} |
| 41 | + ) |
| 42 | +
|
| 43 | + >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
| 44 | + ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTaskProxyLess, |
| 45 | + ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
| 46 | + ... ).captcha_handler() |
| 47 | + CaptchaResponseSer(errorId=0, |
| 48 | + errorCode=None, |
| 49 | + errorDescription=None, |
| 50 | + taskId='73bdcd28-6c77-4414-8....', |
| 51 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 52 | + solution={'cookie': '44795sds...'} |
| 53 | + ) |
| 54 | +
|
| 55 | + >>> AwsWaf(api_key="CAI-BA9XXXXXXXXXXXXX2702E010", |
| 56 | + ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTask, |
| 57 | + ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
| 58 | + ... proxy="socks5:192.191.100.10:4780:user:pwd", |
| 59 | + ... awsKey="some key" |
| 60 | + ... ).captcha_handler() |
| 61 | + CaptchaResponseSer(errorId=0, |
| 62 | + errorCode=None, |
| 63 | + errorDescription=None, |
| 64 | + taskId="87f149f4-1c....", |
| 65 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 66 | + solution={'cookie': '44795sds...'} |
| 67 | + ) |
| 68 | +
|
| 69 | + >>> await AwsWaf(api_key="CAI-BA9650D2B9C2786B21120D512702E010", |
| 70 | + ... captcha_type=AntiAwsWafTaskTypeEnm.AntiAwsWafTaskProxyLess, |
| 71 | + ... websiteURL="https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest", |
| 72 | + ... ).aio_captcha_handler() |
| 73 | + CaptchaResponseSer(errorId=0, |
| 74 | + errorCode=None, |
| 75 | + errorDescription=None, |
| 76 | + taskId='73bdcd28-6c77-4414-8....', |
| 77 | + status=<ResponseStatusEnm.Ready: 'ready'>, |
| 78 | + solution={'cookie': '44795sds...'} |
| 79 | + ) |
67 | 80 |
|
68 | | - Returns: |
69 | | - CaptchaResponseSer model with full server response |
| 81 | + Returns: |
| 82 | + CaptchaResponseSer model with full server response |
70 | 83 |
|
71 | | - Notes: |
72 | | - https://docs.capsolver.com/guide/captcha/awsWaf.html |
73 | | - """ |
| 84 | + Notes: |
| 85 | + https://docs.capsolver.com/guide/captcha/awsWaf.html |
| 86 | + """ |
74 | 87 |
|
75 | | - def __init__(self, captcha_type: Union[AntiAwsWafTaskTypeEnm, str], websiteURL: str, *args, **kwargs): |
76 | | - super().__init__(*args, **kwargs) |
| 88 | + super().__init__(api_key=api_key, sleep_time=sleep_time) |
77 | 89 |
|
78 | 90 | if captcha_type in AntiAwsWafTaskTypeEnm.list(): |
79 | | - self.task_params = WebsiteDataOptionsSer(**locals()).dict() |
| 91 | + self.task_params.update(dict(type=captcha_type, websiteURL=websiteURL, **additional_params)) |
80 | 92 | else: |
81 | 93 | raise ValueError( |
82 | 94 | f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, |
83 | 95 | available - {AntiAwsWafTaskTypeEnm.list_values()}""" |
84 | 96 | ) |
85 | | - |
86 | | - for key in kwargs: |
87 | | - self.task_params.update({key: kwargs[key]}) |
88 | | - |
89 | | - def captcha_handler(self) -> CaptchaResponseSer: |
90 | | - """ |
91 | | - Sync solving method |
92 | | -
|
93 | | - Returns: |
94 | | - CaptchaResponseSer model with full service response |
95 | | -
|
96 | | - Notes: |
97 | | - Check class docstring for more info |
98 | | - """ |
99 | | - return self._processing_captcha(create_params=self.task_params) |
100 | | - |
101 | | - async def aio_captcha_handler(self) -> CaptchaResponseSer: |
102 | | - """ |
103 | | - Async method for captcha solving |
104 | | -
|
105 | | - Returns: |
106 | | - CaptchaResponseSer model with full service response |
107 | | -
|
108 | | - Notes: |
109 | | - Check class docstring for more info |
110 | | - """ |
111 | | - return await self._aio_processing_captcha(create_params=self.task_params) |
0 commit comments