python-rucaptcha 6.7.0__tar.gz → 6.8.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.
Files changed (97) hide show
  1. {python_rucaptcha-6.7.0/src/python_rucaptcha.egg-info → python_rucaptcha-6.8.1}/PKG-INFO +6 -2
  2. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/README.md +4 -0
  3. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/pyproject.toml +18 -1
  4. python_rucaptcha-6.8.1/src/python_rucaptcha/__version__.py +1 -0
  5. python_rucaptcha-6.8.1/src/python_rucaptcha/alibaba_captcha.py +94 -0
  6. python_rucaptcha-6.8.1/src/python_rucaptcha/basilisk_captcha.py +72 -0
  7. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/base.py +2 -2
  8. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/enums.py +18 -0
  9. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/result_handler.py +2 -2
  10. python_rucaptcha-6.8.1/src/python_rucaptcha/incapsula_captcha.py +75 -0
  11. python_rucaptcha-6.8.1/src/python_rucaptcha/tspd_captcha.py +73 -0
  12. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/vk_captcha.py +8 -2
  13. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1/src/python_rucaptcha.egg-info}/PKG-INFO +6 -2
  14. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha.egg-info/SOURCES.txt +8 -0
  15. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha.egg-info/requires.txt +1 -1
  16. python_rucaptcha-6.8.1/tests/test_alibaba.py +65 -0
  17. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_altcha.py +2 -2
  18. python_rucaptcha-6.8.1/tests/test_basilisk.py +55 -0
  19. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_image.py +8 -8
  20. python_rucaptcha-6.8.1/tests/test_incapsula.py +62 -0
  21. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_rotate.py +10 -10
  22. python_rucaptcha-6.8.1/tests/test_tspd.py +60 -0
  23. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_yandex_smart_captcha.py +4 -2
  24. python_rucaptcha-6.7.0/src/python_rucaptcha/__version__.py +0 -1
  25. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/LICENSE +0 -0
  26. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/MANIFEST.in +0 -0
  27. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/setup.cfg +0 -0
  28. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/__init__.py +0 -0
  29. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/altcha_captcha.py +0 -0
  30. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/amazon_waf.py +0 -0
  31. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/atb_captcha.py +0 -0
  32. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/audio_captcha.py +0 -0
  33. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/binance_captcha.py +0 -0
  34. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/bounding_box_captcha.py +0 -0
  35. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/captcha_fox.py +0 -0
  36. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/captchaai.py +0 -0
  37. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/capy_puzzle.py +0 -0
  38. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/control.py +0 -0
  39. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/coordinates_captcha.py +0 -0
  40. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/__init__.py +0 -0
  41. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/captchaai.py +0 -0
  42. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/config.py +0 -0
  43. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/data/__init__.py +0 -0
  44. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/data/captchaai_legacy_profiles.json +0 -0
  45. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/data/captchaai_profiles.json +0 -0
  46. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/core/serializer.py +0 -0
  47. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/cutcaptcha.py +0 -0
  48. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/cyber_siara_captcha.py +0 -0
  49. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/datadome_captcha.py +0 -0
  50. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/draw_around_captcha.py +0 -0
  51. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/friendly_captcha.py +0 -0
  52. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/fun_captcha.py +0 -0
  53. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/gee_test.py +0 -0
  54. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/grid_captcha.py +0 -0
  55. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/hcaptcha.py +0 -0
  56. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/image_captcha.py +0 -0
  57. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/key_captcha.py +0 -0
  58. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/lemin_captcha.py +0 -0
  59. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/mt_captcha.py +0 -0
  60. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/prosopo.py +0 -0
  61. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/re_captcha.py +0 -0
  62. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/rotate_captcha.py +0 -0
  63. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/temu_captcha.py +0 -0
  64. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/tencent.py +0 -0
  65. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/text_captcha.py +0 -0
  66. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/turnstile.py +0 -0
  67. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/yandex_smart_captcha.py +0 -0
  68. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha/yidun_captcha.py +0 -0
  69. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha.egg-info/dependency_links.txt +0 -0
  70. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/src/python_rucaptcha.egg-info/top_level.txt +0 -0
  71. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_amazon.py +0 -0
  72. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_audio.py +0 -0
  73. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_binance.py +0 -0
  74. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_bounding_box.py +0 -0
  75. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_captchaai.py +0 -0
  76. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_capypuzzle.py +0 -0
  77. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_control.py +0 -0
  78. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_coordinates.py +0 -0
  79. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_core.py +0 -0
  80. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_cutcaptcha.py +0 -0
  81. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_cybersiara.py +0 -0
  82. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_datadome.py +0 -0
  83. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_draw_around.py +0 -0
  84. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_friendly_captcha.py +0 -0
  85. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_funcaptcha.py +0 -0
  86. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_geetest.py +0 -0
  87. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_grid.py +0 -0
  88. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_hcaptcha.py +0 -0
  89. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_key_captcha.py +0 -0
  90. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_lemin.py +0 -0
  91. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_mtcaptcha.py +0 -0
  92. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_recaptcha.py +0 -0
  93. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_tencent.py +0 -0
  94. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_text.py +0 -0
  95. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_turnstile.py +0 -0
  96. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_vk_captcha.py +0 -0
  97. {python_rucaptcha-6.7.0 → python_rucaptcha-6.8.1}/tests/test_yidun_captcha.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-rucaptcha
3
- Version: 6.7.0
3
+ Version: 6.8.1
4
4
  Summary: Python 3.9+ RuCaptcha library with AIO module.
5
5
  Author-email: AndreiDrang <python-captcha@pm.me>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
28
28
  License-File: LICENSE
29
29
  Requires-Dist: requests>=2.21.0
30
30
  Requires-Dist: aiohttp>=3.9.2
31
- Requires-Dist: msgspec<0.21,>=0.18
31
+ Requires-Dist: msgspec<0.23,>=0.18
32
32
  Requires-Dist: tenacity<10,>=8
33
33
  Dynamic: license-file
34
34
 
@@ -198,6 +198,10 @@ token = asyncio.run(solve())
198
198
  | KeyCaptcha | `KeyCaptcha` | KeyCAPTCHA service |
199
199
  | Amazon WAF | `AmazonWaf` | AWS WAF challenge |
200
200
  | ALTCHA | `AltchaCaptcha` | ALTCHA challenge |
201
+ | TSPD | `TSPDCaptcha` | Cookie-based TSPD protection |
202
+ | Basilisk | `BasiliskCaptcha` | Token-based Basilisk challenge |
203
+ | Alibaba | `AlibabaCaptcha` | Token-based Alibaba challenge |
204
+ | Imperva/Incapsula | `IncapsulaCaptcha` | Cookie-based Imperva protection |
201
205
  | Binance | `BinanceCaptcha` | Token-based Binance challenge |
202
206
  | Grid | `GridCaptcha` | Select grid cells |
203
207
  | Coordinates | `CoordinatesCaptcha` | Click on coordinates |
@@ -164,6 +164,10 @@ token = asyncio.run(solve())
164
164
  | KeyCaptcha | `KeyCaptcha` | KeyCAPTCHA service |
165
165
  | Amazon WAF | `AmazonWaf` | AWS WAF challenge |
166
166
  | ALTCHA | `AltchaCaptcha` | ALTCHA challenge |
167
+ | TSPD | `TSPDCaptcha` | Cookie-based TSPD protection |
168
+ | Basilisk | `BasiliskCaptcha` | Token-based Basilisk challenge |
169
+ | Alibaba | `AlibabaCaptcha` | Token-based Alibaba challenge |
170
+ | Imperva/Incapsula | `IncapsulaCaptcha` | Cookie-based Imperva protection |
167
171
  | Binance | `BinanceCaptcha` | Token-based Binance challenge |
168
172
  | Grid | `GridCaptcha` | Select grid cells |
169
173
  | Coordinates | `CoordinatesCaptcha` | Click on coordinates |
@@ -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
  ]
@@ -91,7 +92,7 @@ classifiers = [
91
92
  dependencies = [
92
93
  "requests>=2.21.0",
93
94
  "aiohttp>=3.9.2",
94
- "msgspec>=0.18,<0.21",
95
+ "msgspec>=0.18,<0.23",
95
96
  "tenacity>=8,<10"
96
97
  ]
97
98
 
@@ -111,3 +112,19 @@ Documentation = "https://andreidrang.github.io/python-rucaptcha/"
111
112
  Repository = "https://github.com/AndreiDrang/python-rucaptcha"
112
113
  Issues = "https://github.com/AndreiDrang/python-rucaptcha/issues"
113
114
  Changelog = "https://github.com/AndreiDrang/python-rucaptcha/releases"
115
+
116
+ [dependency-groups]
117
+ dev = [
118
+ "autoflake>=2.3.1",
119
+ "black>=24.8.0",
120
+ "coverage>=7.6.1",
121
+ "isort>=5.13.2",
122
+ "pytest>=8.3.5",
123
+ "pytest-asyncio>=0.24.0",
124
+ ]
125
+ docs = [
126
+ "enum-tools[sphinx]>=0.13.0",
127
+ "myst-parser>=3.0.1",
128
+ "pallets-sphinx-themes>=2.3.0",
129
+ "sphinx>=7.1.2,<9", # <9: enum-tools 0.13 cannot import from Sphinx 9
130
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "6.8.1"
@@ -0,0 +1,94 @@
1
+ from typing import Union, Optional
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import AlibabaEnm
5
+
6
+
7
+ class AlibabaCaptcha(BaseCaptcha):
8
+ """Solve Alibaba captcha with a proxyless or customer-provided proxy task."""
9
+
10
+ def __init__(
11
+ self,
12
+ websiteURL: str,
13
+ sceneId: str,
14
+ prefix: str,
15
+ method: Union[str, AlibabaEnm] = AlibabaEnm.AlibabaTaskProxyless,
16
+ userId: Optional[str] = None,
17
+ userUserId: Optional[str] = None,
18
+ verifyType: Optional[str] = None,
19
+ region: Optional[str] = None,
20
+ userCertifyId: Optional[str] = None,
21
+ apiGetLib: Optional[str] = None,
22
+ userAgent: Optional[str] = None,
23
+ proxyType: Optional[str] = None,
24
+ proxyAddress: Optional[str] = None,
25
+ proxyPort: Optional[int] = None,
26
+ proxyLogin: Optional[str] = None,
27
+ proxyPassword: Optional[str] = None,
28
+ *args,
29
+ **kwargs,
30
+ ):
31
+ """
32
+ Args:
33
+ rucaptcha_key: User API key.
34
+ websiteURL: Full URL of the page where Alibaba captcha is loaded.
35
+ sceneId: Captcha scenario identifier.
36
+ prefix: Captcha initialization prefix from the loading request.
37
+ method: ``AlibabaTaskProxyless`` or ``AlibabaTask``.
38
+ userId: Optional website-side user or session identifier.
39
+ userUserId: Optional secondary user identifier.
40
+ verifyType: Optional verification mechanism type.
41
+ region: Optional Alibaba processing region.
42
+ userCertifyId: Optional verification identifier.
43
+ apiGetLib: Optional URL of the captcha JavaScript library.
44
+ userAgent: Optional browser User-Agent.
45
+ proxyType: Proxy type for ``AlibabaTask``.
46
+ proxyAddress: Proxy IP address or hostname.
47
+ proxyPort: Proxy port.
48
+ proxyLogin: Optional proxy login.
49
+ proxyPassword: Optional proxy password.
50
+ kwargs: Additional task parameters.
51
+ """
52
+ super().__init__(method=method, *args, **kwargs)
53
+
54
+ if method not in AlibabaEnm.list_values():
55
+ raise ValueError(f"Invalid method parameter set, available - {AlibabaEnm.list_values()}")
56
+
57
+ task_data = {"websiteURL": websiteURL, "sceneId": sceneId, "prefix": prefix}
58
+ optional_data = {
59
+ "userId": userId,
60
+ "userUserId": userUserId,
61
+ "verifyType": verifyType,
62
+ "region": region,
63
+ "userCertifyId": userCertifyId,
64
+ "apiGetLib": apiGetLib,
65
+ "userAgent": userAgent,
66
+ }
67
+ task_data.update({key: value for key, value in optional_data.items() if value is not None})
68
+
69
+ if method == AlibabaEnm.AlibabaTask.value:
70
+ if not all([proxyType, proxyAddress, proxyPort]):
71
+ raise ValueError(
72
+ "Proxy parameters (proxyType, proxyAddress, proxyPort) are required for AlibabaTask"
73
+ )
74
+ task_data.update(
75
+ {
76
+ "proxyType": proxyType,
77
+ "proxyAddress": proxyAddress,
78
+ "proxyPort": proxyPort,
79
+ }
80
+ )
81
+ if proxyLogin is not None:
82
+ task_data["proxyLogin"] = proxyLogin
83
+ if proxyPassword is not None:
84
+ task_data["proxyPassword"] = proxyPassword
85
+
86
+ self.create_task_payload["task"].update(task_data)
87
+
88
+ def captcha_handler(self, **kwargs) -> dict:
89
+ """Synchronously submit and poll the Alibaba task."""
90
+ return self._processing_response(**kwargs)
91
+
92
+ async def aio_captcha_handler(self) -> dict:
93
+ """Asynchronously submit and poll the Alibaba task."""
94
+ return await self._aio_processing_response()
@@ -0,0 +1,72 @@
1
+ from typing import Union, Optional
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import BasiliskEnm
5
+
6
+
7
+ class BasiliskCaptcha(BaseCaptcha):
8
+ """Solve Basilisk captcha with a proxyless or customer-provided proxy task."""
9
+
10
+ def __init__(
11
+ self,
12
+ websiteURL: str,
13
+ websiteKey: str,
14
+ method: Union[str, BasiliskEnm] = BasiliskEnm.BasiliskTaskProxyless,
15
+ userAgent: Optional[str] = None,
16
+ proxyType: Optional[str] = None,
17
+ proxyAddress: Optional[str] = None,
18
+ proxyPort: Optional[int] = None,
19
+ proxyLogin: Optional[str] = None,
20
+ proxyPassword: Optional[str] = None,
21
+ *args,
22
+ **kwargs,
23
+ ):
24
+ """
25
+ Args:
26
+ rucaptcha_key: User API key.
27
+ websiteURL: Full URL of the page where Basilisk is loaded.
28
+ websiteKey: The page's Basilisk data-sitekey value.
29
+ method: ``BasiliskTaskProxyless`` or ``BasiliskTask``.
30
+ userAgent: Optional browser User-Agent.
31
+ proxyType: Proxy type for ``BasiliskTask``.
32
+ proxyAddress: Proxy IP address or hostname.
33
+ proxyPort: Proxy port.
34
+ proxyLogin: Optional proxy login.
35
+ proxyPassword: Optional proxy password.
36
+ kwargs: Additional task parameters.
37
+ """
38
+ super().__init__(method=method, *args, **kwargs)
39
+
40
+ if method not in BasiliskEnm.list_values():
41
+ raise ValueError(f"Invalid method parameter set, available - {BasiliskEnm.list_values()}")
42
+
43
+ task_data = {"websiteURL": websiteURL, "websiteKey": websiteKey}
44
+ if userAgent is not None:
45
+ task_data["userAgent"] = userAgent
46
+
47
+ if method == BasiliskEnm.BasiliskTask.value:
48
+ if not all([proxyType, proxyAddress, proxyPort]):
49
+ raise ValueError(
50
+ "Proxy parameters (proxyType, proxyAddress, proxyPort) are required for BasiliskTask"
51
+ )
52
+ task_data.update(
53
+ {
54
+ "proxyType": proxyType,
55
+ "proxyAddress": proxyAddress,
56
+ "proxyPort": proxyPort,
57
+ }
58
+ )
59
+ if proxyLogin is not None:
60
+ task_data["proxyLogin"] = proxyLogin
61
+ if proxyPassword is not None:
62
+ task_data["proxyPassword"] = proxyPassword
63
+
64
+ self.create_task_payload["task"].update(task_data)
65
+
66
+ def captcha_handler(self, **kwargs) -> dict:
67
+ """Synchronously submit and poll the Basilisk task."""
68
+ return self._processing_response(**kwargs)
69
+
70
+ async def aio_captcha_handler(self) -> dict:
71
+ """Asynchronously submit and poll the Basilisk task."""
72
+ return await self._aio_processing_response()
@@ -104,7 +104,7 @@ class BaseCaptcha:
104
104
  return response.to_dict()
105
105
  except Exception as error:
106
106
  self.result.errorId = 12
107
- self.result.errorCode = self.NO_CAPTCHA_ERR
107
+ self.result.errorCode = "ERROR_CAPTCHA_UNSOLVABLE"
108
108
  self.result.errorDescription = str(error)
109
109
  return self.result.to_dict()
110
110
 
@@ -157,7 +157,7 @@ class BaseCaptcha:
157
157
  return response.to_dict()
158
158
  except Exception as error:
159
159
  self.result.errorId = 12
160
- self.result.errorCode = self.NO_CAPTCHA_ERR
160
+ self.result.errorCode = "ERROR_CAPTCHA_UNSOLVABLE"
161
161
  self.result.errorDescription = str(error)
162
162
  return self.result.to_dict()
163
163
 
@@ -191,6 +191,24 @@ class BinanceCaptchaEnm(str, MyEnum):
191
191
  BinanceTask = "BinanceTask"
192
192
 
193
193
 
194
+ class TSPDEnm(str, MyEnum):
195
+ TspdTask = "tspdtask"
196
+
197
+
198
+ class BasiliskEnm(str, MyEnum):
199
+ BasiliskTaskProxyless = "BasiliskTaskProxyless"
200
+ BasiliskTask = "BasiliskTask"
201
+
202
+
203
+ class AlibabaEnm(str, MyEnum):
204
+ AlibabaTaskProxyless = "AlibabaTaskProxyless"
205
+ AlibabaTask = "AlibabaTask"
206
+
207
+
208
+ class IncapsulaEnm(str, MyEnum):
209
+ IncapsulaTask = "IncapsulaTask"
210
+
211
+
194
212
  class YidunEnm(str, MyEnum):
195
213
  YidunTaskProxyless = "YidunTaskProxyless"
196
214
  YidunTask = "YidunTask"
@@ -55,7 +55,7 @@ def get_sync_result(
55
55
  except Exception as error:
56
56
  response_ser.status = "failed"
57
57
  response_ser.errorId = 12
58
- response_ser.errorCode = "System error"
58
+ response_ser.errorCode = "ERROR_CAPTCHA_UNSOLVABLE"
59
59
  response_ser.errorDescription = str(error)
60
60
  return response_ser.to_dict()
61
61
 
@@ -110,6 +110,6 @@ async def get_async_result(
110
110
  except Exception as error:
111
111
  response_ser.status = "failed"
112
112
  response_ser.errorId = 12
113
- response_ser.errorCode = "System error"
113
+ response_ser.errorCode = "ERROR_CAPTCHA_UNSOLVABLE"
114
114
  response_ser.errorDescription = str(error)
115
115
  return response_ser.to_dict()
@@ -0,0 +1,75 @@
1
+ from typing import Union, Optional
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import IncapsulaEnm
5
+
6
+
7
+ class IncapsulaCaptcha(BaseCaptcha):
8
+ """Solve the cookie-based Imperva (Incapsula) captcha."""
9
+
10
+ def __init__(
11
+ self,
12
+ websiteURL: str,
13
+ incapsulaScriptUrl: str,
14
+ incapsulaCookies: str,
15
+ proxyType: str,
16
+ proxyAddress: str,
17
+ proxyPort: int,
18
+ method: Union[str, IncapsulaEnm] = IncapsulaEnm.IncapsulaTask,
19
+ userAgent: Optional[str] = None,
20
+ reese84UrlEndpoint: Optional[str] = None,
21
+ proxyLogin: Optional[str] = None,
22
+ proxyPassword: Optional[str] = None,
23
+ *args,
24
+ **kwargs,
25
+ ):
26
+ """
27
+ Args:
28
+ rucaptcha_key: User API key.
29
+ websiteURL: Full URL of the page where Incapsula is loaded.
30
+ incapsulaScriptUrl: Incapsula JavaScript resource URL or name.
31
+ incapsulaCookies: Cookies received from the Incapsula challenge page.
32
+ proxyType: Proxy type: ``http``, ``socks4`` or ``socks5``.
33
+ proxyAddress: Proxy IP address or hostname.
34
+ proxyPort: Proxy port.
35
+ method: Captcha task type. Only ``IncapsulaTask`` is supported.
36
+ userAgent: Optional browser User-Agent.
37
+ reese84UrlEndpoint: Optional Reese84 fingerprint endpoint.
38
+ proxyLogin: Optional proxy login.
39
+ proxyPassword: Optional proxy password.
40
+ kwargs: Additional task parameters.
41
+ """
42
+ super().__init__(method=method, *args, **kwargs)
43
+
44
+ if method not in IncapsulaEnm.list_values():
45
+ raise ValueError(f"Invalid method parameter set, available - {IncapsulaEnm.list_values()}")
46
+
47
+ task_data = {
48
+ "websiteURL": websiteURL,
49
+ "incapsulaScriptUrl": incapsulaScriptUrl,
50
+ "incapsulaCookies": incapsulaCookies,
51
+ "proxyType": proxyType,
52
+ "proxyAddress": proxyAddress,
53
+ "proxyPort": proxyPort,
54
+ }
55
+ optional_data = {
56
+ "userAgent": userAgent,
57
+ "reese84UrlEndpoint": reese84UrlEndpoint,
58
+ "proxyLogin": proxyLogin,
59
+ "proxyPassword": proxyPassword,
60
+ }
61
+ task_data.update({key: value for key, value in optional_data.items() if value is not None})
62
+ self.create_task_payload["task"].update(task_data)
63
+
64
+ def captcha_handler(self, **kwargs) -> dict:
65
+ """Synchronously submit and poll the Incapsula task."""
66
+ return self._processing_response(**kwargs)
67
+
68
+ async def aio_captcha_handler(self) -> dict:
69
+ """Asynchronously submit and poll the Incapsula task."""
70
+ return await self._aio_processing_response()
71
+
72
+
73
+ # Imperva is the product name; keep an intuitive alias alongside the API name.
74
+ ImpervaCaptcha = IncapsulaCaptcha
75
+ ImpervaEnm = IncapsulaEnm
@@ -0,0 +1,73 @@
1
+ from typing import Union, Optional
2
+
3
+ from .core.base import BaseCaptcha
4
+ from .core.enums import TSPDEnm
5
+
6
+
7
+ class TSPDCaptcha(BaseCaptcha):
8
+ """Solve the cookie-based TSPD captcha using a static proxy session."""
9
+
10
+ def __init__(
11
+ self,
12
+ websiteURL: str,
13
+ tspdcookie: str,
14
+ htmlPageBase64: str,
15
+ proxyType: str,
16
+ proxyAddress: str,
17
+ proxyPort: int,
18
+ method: Union[str, TSPDEnm] = TSPDEnm.TspdTask,
19
+ proxyLogin: Optional[str] = None,
20
+ proxyPassword: Optional[str] = None,
21
+ userAgent: Optional[str] = None,
22
+ *args,
23
+ **kwargs,
24
+ ):
25
+ """
26
+ Args:
27
+ rucaptcha_key: User API key.
28
+ websiteURL: Full URL of the page where TSPD is loaded.
29
+ tspdcookie: Cookies received from the TSPD challenge page.
30
+ htmlPageBase64: Full challenge-page HTML encoded as Base64.
31
+ proxyType: Proxy type: ``http``, ``socks4`` or ``socks5``.
32
+ proxyAddress: Proxy IP address or hostname.
33
+ proxyPort: Proxy port.
34
+ method: Captcha task type. Only ``tspdtask`` is supported.
35
+ proxyLogin: Optional proxy login.
36
+ proxyPassword: Optional proxy password.
37
+ userAgent: Browser User-Agent used to load the page.
38
+ kwargs: Additional task parameters.
39
+
40
+ Notes:
41
+ The proxy must use a static session and the same outbound IP must be
42
+ maintained while obtaining cookies, solving the task, and using the
43
+ returned cookies.
44
+ """
45
+ super().__init__(method=method, *args, **kwargs)
46
+
47
+ if method not in TSPDEnm.list_values():
48
+ raise ValueError(f"Invalid method parameter set, available - {TSPDEnm.list_values()}")
49
+
50
+ task_data = {
51
+ "websiteURL": websiteURL,
52
+ "tspdcookie": tspdcookie,
53
+ "htmlPageBase64": htmlPageBase64,
54
+ "proxyType": proxyType,
55
+ "proxyAddress": proxyAddress,
56
+ "proxyPort": proxyPort,
57
+ }
58
+ if proxyLogin is not None:
59
+ task_data["proxyLogin"] = proxyLogin
60
+ if proxyPassword is not None:
61
+ task_data["proxyPassword"] = proxyPassword
62
+ if userAgent is not None:
63
+ task_data["userAgent"] = userAgent
64
+
65
+ self.create_task_payload["task"].update(task_data)
66
+
67
+ def captcha_handler(self, **kwargs) -> dict:
68
+ """Synchronously submit and poll the TSPD task."""
69
+ return self._processing_response(**kwargs)
70
+
71
+ async def aio_captcha_handler(self) -> dict:
72
+ """Asynchronously submit and poll the TSPD task."""
73
+ return await self._aio_processing_response()
@@ -7,7 +7,7 @@ from .core.enums import VKCaptchaEnm, SaveFormatsEnm
7
7
  class VKCaptcha(BaseCaptcha):
8
8
  def __init__(
9
9
  self,
10
- method: Union[str, VKCaptchaEnm] = VKCaptchaEnm.VKCaptchaTask,
10
+ method: Union[str, VKCaptchaEnm, None] = None,
11
11
  redirectUri: Optional[str] = None,
12
12
  userAgent: Optional[str] = None,
13
13
  proxyType: Optional[str] = None,
@@ -113,6 +113,12 @@ class VKCaptcha(BaseCaptcha):
113
113
 
114
114
  https://rucaptcha.com/api-docs/vk-captcha
115
115
  """
116
+ # VKCaptchaTask is the default task type. Its required fields are only
117
+ # validated when VKCaptchaTask is selected explicitly via ``method``.
118
+ method_passed = method is not None
119
+ if method is None:
120
+ method = VKCaptchaEnm.VKCaptchaTask
121
+
116
122
  super().__init__(method=method, *args, **kwargs)
117
123
 
118
124
  if method not in VKCaptchaEnm.list_values():
@@ -123,7 +129,7 @@ class VKCaptcha(BaseCaptcha):
123
129
  self.img_path = img_path
124
130
 
125
131
  if method == VKCaptchaEnm.VKCaptchaTask:
126
- if not all([redirectUri, userAgent, proxyType, proxyAddress, proxyPort]):
132
+ if method_passed and not all([redirectUri, userAgent, proxyType, proxyAddress, proxyPort]):
127
133
  raise ValueError(
128
134
  "redirectUri, userAgent, proxyType, proxyAddress, "
129
135
  "and proxyPort are required for VKCaptchaTask"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-rucaptcha
3
- Version: 6.7.0
3
+ Version: 6.8.1
4
4
  Summary: Python 3.9+ RuCaptcha library with AIO module.
5
5
  Author-email: AndreiDrang <python-captcha@pm.me>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ Description-Content-Type: text/markdown
28
28
  License-File: LICENSE
29
29
  Requires-Dist: requests>=2.21.0
30
30
  Requires-Dist: aiohttp>=3.9.2
31
- Requires-Dist: msgspec<0.21,>=0.18
31
+ Requires-Dist: msgspec<0.23,>=0.18
32
32
  Requires-Dist: tenacity<10,>=8
33
33
  Dynamic: license-file
34
34
 
@@ -198,6 +198,10 @@ token = asyncio.run(solve())
198
198
  | KeyCaptcha | `KeyCaptcha` | KeyCAPTCHA service |
199
199
  | Amazon WAF | `AmazonWaf` | AWS WAF challenge |
200
200
  | ALTCHA | `AltchaCaptcha` | ALTCHA challenge |
201
+ | TSPD | `TSPDCaptcha` | Cookie-based TSPD protection |
202
+ | Basilisk | `BasiliskCaptcha` | Token-based Basilisk challenge |
203
+ | Alibaba | `AlibabaCaptcha` | Token-based Alibaba challenge |
204
+ | Imperva/Incapsula | `IncapsulaCaptcha` | Cookie-based Imperva protection |
201
205
  | Binance | `BinanceCaptcha` | Token-based Binance challenge |
202
206
  | Grid | `GridCaptcha` | Select grid cells |
203
207
  | Coordinates | `CoordinatesCaptcha` | Click on coordinates |
@@ -4,10 +4,12 @@ README.md
4
4
  pyproject.toml
5
5
  src/python_rucaptcha/__init__.py
6
6
  src/python_rucaptcha/__version__.py
7
+ src/python_rucaptcha/alibaba_captcha.py
7
8
  src/python_rucaptcha/altcha_captcha.py
8
9
  src/python_rucaptcha/amazon_waf.py
9
10
  src/python_rucaptcha/atb_captcha.py
10
11
  src/python_rucaptcha/audio_captcha.py
12
+ src/python_rucaptcha/basilisk_captcha.py
11
13
  src/python_rucaptcha/binance_captcha.py
12
14
  src/python_rucaptcha/bounding_box_captcha.py
13
15
  src/python_rucaptcha/captcha_fox.py
@@ -25,6 +27,7 @@ src/python_rucaptcha/gee_test.py
25
27
  src/python_rucaptcha/grid_captcha.py
26
28
  src/python_rucaptcha/hcaptcha.py
27
29
  src/python_rucaptcha/image_captcha.py
30
+ src/python_rucaptcha/incapsula_captcha.py
28
31
  src/python_rucaptcha/key_captcha.py
29
32
  src/python_rucaptcha/lemin_captcha.py
30
33
  src/python_rucaptcha/mt_captcha.py
@@ -34,6 +37,7 @@ src/python_rucaptcha/rotate_captcha.py
34
37
  src/python_rucaptcha/temu_captcha.py
35
38
  src/python_rucaptcha/tencent.py
36
39
  src/python_rucaptcha/text_captcha.py
40
+ src/python_rucaptcha/tspd_captcha.py
37
41
  src/python_rucaptcha/turnstile.py
38
42
  src/python_rucaptcha/vk_captcha.py
39
43
  src/python_rucaptcha/yandex_smart_captcha.py
@@ -53,9 +57,11 @@ src/python_rucaptcha/core/serializer.py
53
57
  src/python_rucaptcha/core/data/__init__.py
54
58
  src/python_rucaptcha/core/data/captchaai_legacy_profiles.json
55
59
  src/python_rucaptcha/core/data/captchaai_profiles.json
60
+ tests/test_alibaba.py
56
61
  tests/test_altcha.py
57
62
  tests/test_amazon.py
58
63
  tests/test_audio.py
64
+ tests/test_basilisk.py
59
65
  tests/test_binance.py
60
66
  tests/test_bounding_box.py
61
67
  tests/test_captchaai.py
@@ -73,6 +79,7 @@ tests/test_geetest.py
73
79
  tests/test_grid.py
74
80
  tests/test_hcaptcha.py
75
81
  tests/test_image.py
82
+ tests/test_incapsula.py
76
83
  tests/test_key_captcha.py
77
84
  tests/test_lemin.py
78
85
  tests/test_mtcaptcha.py
@@ -80,6 +87,7 @@ tests/test_recaptcha.py
80
87
  tests/test_rotate.py
81
88
  tests/test_tencent.py
82
89
  tests/test_text.py
90
+ tests/test_tspd.py
83
91
  tests/test_turnstile.py
84
92
  tests/test_vk_captcha.py
85
93
  tests/test_yandex_smart_captcha.py
@@ -1,4 +1,4 @@
1
1
  requests>=2.21.0
2
2
  aiohttp>=3.9.2
3
- msgspec<0.21,>=0.18
3
+ msgspec<0.23,>=0.18
4
4
  tenacity<10,>=8
@@ -0,0 +1,65 @@
1
+ import pytest
2
+
3
+ from python_rucaptcha.core.enums import AlibabaEnm
4
+ from python_rucaptcha.alibaba_captcha import AlibabaCaptcha
5
+
6
+ KEY = "test-key"
7
+
8
+
9
+ class TestAlibabaCaptcha:
10
+ def test_methods_exist(self):
11
+ assert "captcha_handler" in AlibabaCaptcha.__dict__
12
+ assert "aio_captcha_handler" in AlibabaCaptcha.__dict__
13
+
14
+ @pytest.mark.parametrize("method", AlibabaEnm.list_values())
15
+ def test_payload(self, method):
16
+ proxy = {}
17
+ if method == AlibabaEnm.AlibabaTask.value:
18
+ proxy = {"proxyType": "socks5", "proxyAddress": "203.0.113.10", "proxyPort": 1080}
19
+
20
+ instance = AlibabaCaptcha(
21
+ rucaptcha_key=KEY,
22
+ websiteURL="https://example.com",
23
+ sceneId="scene-123",
24
+ prefix="captcha-prefix",
25
+ method=method,
26
+ userId="user-123",
27
+ userUserId="secondary-user",
28
+ verifyType="verify",
29
+ region="cn",
30
+ userCertifyId="certify-123",
31
+ apiGetLib="https://example.com/captcha.js",
32
+ userAgent="Mozilla/5.0",
33
+ **proxy,
34
+ )
35
+ task = instance.create_task_payload["task"]
36
+
37
+ assert task["type"] == method
38
+ assert task["sceneId"] == "scene-123"
39
+ assert task["prefix"] == "captcha-prefix"
40
+ assert task["userCertifyId"] == "certify-123"
41
+ assert task["apiGetLib"] == "https://example.com/captcha.js"
42
+ if method == AlibabaEnm.AlibabaTask.value:
43
+ assert task["proxyPort"] == 1080
44
+ else:
45
+ assert "proxyPort" not in task
46
+
47
+ def test_proxy_required(self):
48
+ with pytest.raises(ValueError, match="proxyType|proxyAddress|proxyPort"):
49
+ AlibabaCaptcha(
50
+ rucaptcha_key=KEY,
51
+ websiteURL="https://example.com",
52
+ sceneId="scene-123",
53
+ prefix="captcha-prefix",
54
+ method=AlibabaEnm.AlibabaTask,
55
+ )
56
+
57
+ def test_invalid_method(self):
58
+ with pytest.raises(ValueError):
59
+ AlibabaCaptcha(
60
+ rucaptcha_key=KEY,
61
+ websiteURL="https://example.com",
62
+ sceneId="scene-123",
63
+ prefix="captcha-prefix",
64
+ method="invalid",
65
+ )
@@ -136,7 +136,7 @@ class TestAltcha(BaseTest):
136
136
  assert isinstance(result["solution"], dict) is True
137
137
  assert isinstance(result["taskId"], int) is True
138
138
  else:
139
- assert result["errorId"] in (1, 12)
139
+ assert result["errorId"] in (1, 12, 15)
140
140
  assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"
141
141
 
142
142
  assert result.keys() == GetTaskResultResponseSer().to_dict().keys()
@@ -157,7 +157,7 @@ class TestAltcha(BaseTest):
157
157
  assert isinstance(result["solution"], dict) is True
158
158
  assert isinstance(result["taskId"], int) is True
159
159
  else:
160
- assert result["errorId"] in (1, 12)
160
+ assert result["errorId"] in (1, 12, 15)
161
161
  assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"
162
162
 
163
163
  assert result.keys() == GetTaskResultResponseSer().to_dict().keys()