Skip to content

Commit a8b854f

Browse files
author
Andrei
committed
added AntiAkamaiBMPTask
1 parent eeb4204 commit a8b854f

7 files changed

Lines changed: 180 additions & 0 deletions

File tree

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from python3_capsolver import (
77
core,
8+
akamai,
89
gee_test,
910
hcaptcha,
1011
recaptcha,

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The library is intended for software developers and is used to work with the `Ca
3232
modules/cloudflare/example.rst
3333
modules/aws-waf/example.rst
3434
modules/cyber-si-ara/example.rst
35+
modules/akamai/example.rst
3536

3637
.. toctree::
3738
:maxdepth: 2

docs/modules/akamai/example.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Akamai
2+
======
3+
4+
To import this module:
5+
6+
.. code-block:: python
7+
8+
from python3_capsolver.akamai import Akamai
9+
10+
11+
.. autoclass:: python3_capsolver.akamai.Akamai
12+
:members:

docs/modules/serializer/info.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ To import this module:
1616
.. autopydantic_model:: python3_capsolver.core.serializer.WebsiteDataOptionsSer
1717
:members:
1818
:undoc-members:
19+
20+
21+
.. autopydantic_model:: python3_capsolver.core.serializer.CyberSiAraSer
22+
:members:
23+
:undoc-members:
24+
25+
26+
.. autopydantic_model:: python3_capsolver.core.serializer.AntiAkamaiBMPTaskSer
27+
:members:
28+
:undoc-members:

src/python3_capsolver/akamai.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from typing import Union
2+
3+
from python3_capsolver.core.base import BaseCaptcha
4+
from python3_capsolver.core.enum import AntiAkamaiTaskEnm, EndpointPostfixEnm
5+
from python3_capsolver.core.serializer import PostRequestSer, CaptchaResponseSer, AntiAkamaiBMPTaskSer
6+
7+
8+
class Akamai(BaseCaptcha):
9+
"""
10+
The class is used to work with Capsolver AntiAkamai methods.
11+
12+
Args:
13+
api_key: Capsolver API key
14+
captcha_type: Captcha type name, like ``AntiAkamaiBMPTask`` and etc.
15+
packageName: Package name of AkamaiBMP mobile APP
16+
version: AKAMAI BMP Version number, default is: 3.2.6 , max support 3.3.1
17+
18+
Examples:
19+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
20+
... captcha_type="AntiAkamaiBMPTask",
21+
... packageName="de.zalando.iphone",
22+
... country="US",
23+
... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
24+
... deviceName="iPhone14,2/16.0.2",
25+
... count=10,
26+
... ).captcha_handler()
27+
CaptchaResponseSer(errorId=0,
28+
errorCode=None,
29+
errorDescription=None,
30+
taskId='73bdcd28-6c77-4414-8....',
31+
status=<ResponseStatusEnm.Ready: 'ready'>,
32+
solution={'deviceId': '90F9EAF...'}
33+
)
34+
35+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
36+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask,
37+
... ).captcha_handler()
38+
CaptchaResponseSer(errorId=0,
39+
errorCode=None,
40+
errorDescription=None,
41+
taskId='73bdcd28-6c77-4414-8....',
42+
status=<ResponseStatusEnm.Ready: 'ready'>,
43+
solution={'deviceId': '6DKFOD0...'}
44+
)
45+
46+
>>> Akamai(api_key="CAI-BA9XXXXXXXXXXXXX2702E010",
47+
... captcha_type=AntiAkamaiTaskEnm.AntiAkamaiBMPTask,
48+
... **{
49+
... "version": "3.2.6",
50+
... "deviceId": "90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
51+
... "deviceName": "iPhone14,2/16.0.2",
52+
... "count": 10,
53+
... },
54+
... ).captcha_handler()
55+
CaptchaResponseSer(errorId=0,
56+
errorCode=None,
57+
errorDescription=None,
58+
taskId="87f149f4-1c....",
59+
status=<ResponseStatusEnm.Ready: 'ready'>,
60+
solution={'deviceId': '90F9EAF...'}
61+
)
62+
63+
>>> await Akamai(api_key="CAI-BA9650D2B9C2786B21120D512702E010",
64+
... captcha_type="AntiAkamaiBMPTask",
65+
... packageName="de.zalando.iphone",
66+
... country="US",
67+
... deviceId="90F9EAF5-D6E5-4E30-BC8B-B7780AD02600",
68+
... deviceName="iPhone14,2/16.0.2",
69+
... count=10,
70+
... ).aio_captcha_handler()
71+
CaptchaResponseSer(errorId=0,
72+
errorCode=None,
73+
errorDescription=None,
74+
taskId='73bdcd28-6c77-4414-8....',
75+
status=<ResponseStatusEnm.Ready: 'ready'>,
76+
solution={'deviceId': '90F9EAF...'}
77+
)
78+
79+
Returns:
80+
CaptchaResponseSer model with full server response
81+
82+
Notes:
83+
https://docs.capsolver.com/guide/antibots/akamaibmp.html
84+
https://docs.capsolver.com/guide/antibots/akamaiweb.html
85+
"""
86+
87+
serializer = PostRequestSer
88+
89+
def __init__(
90+
self,
91+
captcha_type: Union[AntiAkamaiTaskEnm, str],
92+
packageName: str = "de.zalando.iphone",
93+
version: str = "3.2.6",
94+
country: str = "US",
95+
*args,
96+
**kwargs,
97+
):
98+
super().__init__(*args, **kwargs)
99+
100+
if captcha_type == AntiAkamaiTaskEnm.AntiAkamaiBMPTask:
101+
self.task_params = AntiAkamaiBMPTaskSer(**locals()).dict()
102+
else:
103+
raise ValueError(
104+
f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`,
105+
available - {AntiAkamaiTaskEnm.list_values()}"""
106+
)
107+
108+
for key in kwargs:
109+
self.task_params.update({key: kwargs[key]})
110+
111+
def captcha_handler(self) -> CaptchaResponseSer:
112+
"""
113+
Sync solving method
114+
115+
Returns:
116+
CaptchaResponseSer model with full service response
117+
118+
Notes:
119+
Check class docstring for more info
120+
"""
121+
self._prepare_create_task_payload(serializer=self.serializer, create_params=self.task_params)
122+
return CaptchaResponseSer(
123+
**self._create_task(
124+
url_postfix=EndpointPostfixEnm.AKAMAI_BMP_INVOKE.value,
125+
)
126+
)
127+
128+
async def aio_captcha_handler(self) -> CaptchaResponseSer:
129+
"""
130+
Async method for captcha solving
131+
132+
Returns:
133+
CaptchaResponseSer model with full service response
134+
135+
Notes:
136+
Check class docstring for more info
137+
"""
138+
self._prepare_create_task_payload(serializer=self.serializer, create_params=self.task_params)
139+
return CaptchaResponseSer(
140+
**await self._aio_create_task(
141+
url_postfix=EndpointPostfixEnm.AKAMAI_BMP_INVOKE.value,
142+
)
143+
)

src/python3_capsolver/core/enum.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class EndpointPostfixEnm(str, MyEnum):
3939
GET_BALANCE = "getBalance"
4040
CREATE_TASK = "createTask"
4141
GET_TASK_RESULT = "getTaskResult"
42+
AKAMAI_BMP_INVOKE = "/akamaibmp/invoke"
43+
AKAMAI_WEB_INVOKE = "/akamaiweb/invoke"
4244

4345

4446
class ImageToTextTaskTypeEnm(str, MyEnum):
@@ -110,6 +112,11 @@ class AntiCyberSiAraTaskTypeEnm(str, MyEnum):
110112
AntiCyberSiAraTaskProxyLess = "AntiCyberSiAraTaskProxyLess"
111113

112114

115+
class AntiAkamaiTaskEnm(str, MyEnum):
116+
AntiAkamaiBMPTask = "AntiAkamaiBMPTask"
117+
AntiAkamaiWebTask = "AntiAkamaiWebTask"
118+
119+
113120
class ResponseStatusEnm(str, MyEnum):
114121
"""
115122
Enum store results `status` field variants

src/python3_capsolver/core/serializer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ class CyberSiAraSer(WebsiteDataOptionsSer):
132132
..., description="You can get MasterUrlId param form `api/CyberSiara/GetCyberSiara` endpoint request"
133133
)
134134
UserAgent: str = Field(..., description="Browser userAgent, you need submit your userAgent")
135+
136+
137+
class AntiAkamaiBMPTaskSer(BaseModel):
138+
packageName: str = Field("de.zalando.iphone", description="Package name of AkamaiBMP mobile APP")
139+
version: str = Field("3.2.6", description="AKAMAI BMP Version number")
140+
country: str = Field("US", description="AKAMAI BMP country")

0 commit comments

Comments
 (0)