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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ env/
/src/coverage/lcov.info
/docs/_build/
/coverage/
.osgrep
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ token = asyncio.run(solve())
| KeyCaptcha | `KeyCaptcha` | KeyCAPTCHA service |
| Amazon WAF | `AmazonWaf` | AWS WAF challenge |
| ALTCHA | `AltchaCaptcha` | ALTCHA challenge |
| Binance | `BinanceCaptcha` | Token-based Binance challenge |
| Grid | `GridCaptcha` | Select grid cells |
| Coordinates | `CoordinatesCaptcha` | Click on coordinates |
| And 20+ more | ... | See [full docs](https://andreidrang.github.io/python-rucaptcha/) |
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
image_captcha,
lemin_captcha,
rotate_captcha,
binance_captcha,
datadome_captcha,
friendly_captcha,
cyber_siara_captcha,
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Check our other projects here - `RedPandaDev group <https://red-panda-dev.xyz/bl
modules/tencent/example.rst
modules/prosopo/example.rst
modules/atb-captcha/example.rst
modules/captcha-binance/example.rst
modules/captcha-fox/example.rst
modules/captcha-temu/example.rst
modules/captcha-vk/example.rst
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/captcha-binance/example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BinanceCaptcha
==============

To import this module:

.. code-block:: python

from python_rucaptcha.binance_captcha import BinanceCaptcha


.. autoclass:: python_rucaptcha.binance_captcha.BinanceCaptcha
:members:
3 changes: 3 additions & 0 deletions docs/modules/enum/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ To import this module:

.. autoenum:: python_rucaptcha.core.enums.atbCaptchaEnm
:members:

.. autoenum:: python_rucaptcha.core.enums.BinanceCaptchaEnm
:members:
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pallets_sphinx_themes==2.5.0
myst-parser==5.1.0
enum-tools[sphinx]==0.13.0
requests>=2.32.4 # not directly required, pinned by Snyk to avoid a vulnerability
urllib3>=2.6.3 # not directly required, pinned by Snyk to avoid a vulnerability
urllib3>=2.2.2 # not directly required, pinned by Snyk to avoid a vulnerability
zipp>=3.23.1 # not directly required, pinned by Snyk to avoid a vulnerability
idna>=3.15 # not directly required, pinned by Snyk to avoid a vulnerability
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ keywords = [ "captcha",
"vk-captcha",
"fox-captcha",
"temu-captcha",
"friendly-captcha"
"friendly-captcha",
"binance-captcha"
]
license = "MIT"
classifiers = [
Expand Down
155 changes: 155 additions & 0 deletions src/python_rucaptcha/binance_captcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from typing import Union, Optional

from .core.base import BaseCaptcha
from .core.enums import BinanceCaptchaEnm


class BinanceCaptcha(BaseCaptcha):
def __init__(
self,
websiteURL: str,
websiteKey: str,
validateId: str,
method: Union[str, BinanceCaptchaEnm] = BinanceCaptchaEnm.BinanceTaskProxyless,
userAgent: Optional[str] = None,
proxyType: Optional[str] = None,
proxyAddress: Optional[str] = None,
proxyPort: Optional[int] = None,
proxyLogin: Optional[str] = None,
proxyPassword: Optional[str] = None,
*args,
**kwargs,
):
"""
The class is used to work with Binance CAPTCHA.

Args:
rucaptcha_key: User API key
websiteURL: Full URL of the page where the captcha is loaded
websiteKey: Value of bizId, bizType, or bizCode from page requests
validateId: Dynamic value of validateId, securityId, or securityCheckResponseValidateId
method: Captcha type
userAgent: User-Agent string to be used when solving the captcha
proxyType: Proxy type (http, https, socks4, socks5)
proxyAddress: Proxy IP address or hostname
proxyPort: Proxy port
proxyLogin: Proxy login
proxyPassword: Proxy password

Examples:
>>> BinanceCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... websiteURL="https://example.com/page-with-binance",
... websiteKey="login",
... validateId="cb0bfefa598...e54ecd57b",
... userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
... "(KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
... method=BinanceCaptchaEnm.BinanceTaskProxyless.value,
... ).captcha_handler()
{
"errorId":0,
"status":"ready",
"solution":{
"token":"captcha#09ba4905a79f44f...kc99maS943qIsquNP9D77",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
},
"cost":"0.00299",
"ip":"1.2.3.4",
"createTime":1692863536,
"endTime":1692863556,
"solveCount":1,
"taskId": 73243152973,
}

>>> await BinanceCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... websiteURL="https://example.com/page-with-binance",
... websiteKey="login",
... validateId="cb0bfefa598...e54ecd57b",
... method=BinanceCaptchaEnm.BinanceTask.value,
... proxyType="http",
... proxyAddress="1.2.3.4",
... proxyPort=8080,
... ).aio_captcha_handler()
{
"errorId":0,
"status":"ready",
"solution":{
"token":"captcha#09ba4905a79f44f...kc99maS943qIsquNP9D77",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
},
"cost":"0.00299",
"ip":"1.2.3.4",
"createTime":1692863536,
"endTime":1692863556,
"solveCount":1,
"taskId": 73243152973,
}

Returns:
Dict with full server response

Notes:
https://2captcha.com/api-docs/binance-captcha

https://rucaptcha.com/api-docs/binance-captcha
"""
super().__init__(method=method, *args, **kwargs)

# Validate method
if method not in BinanceCaptchaEnm.list_values():
raise ValueError(f"Invalid method parameter set, available - {BinanceCaptchaEnm.list_values()}")

# Build task payload
task_data = {
"websiteURL": websiteURL,
"websiteKey": websiteKey,
"validateId": validateId,
}

if userAgent:
task_data["userAgent"] = userAgent

# Add proxy params only for non-proxyless methods
if method == BinanceCaptchaEnm.BinanceTask.value:
if not all([proxyType, proxyAddress, proxyPort]):
raise ValueError(
"Proxy parameters (proxyType, proxyAddress, proxyPort) are required for BinanceTask"
)
task_data.update(
{
"proxyType": proxyType,
"proxyAddress": proxyAddress,
"proxyPort": proxyPort,
}
)
if proxyLogin and proxyPassword:
task_data["proxyLogin"] = proxyLogin
task_data["proxyPassword"] = proxyPassword

self.create_task_payload["task"].update(task_data)

def captcha_handler(self, **kwargs) -> dict:
"""
Sync solving method

Args:
kwargs: Parameters for the `requests` library

Returns:
Dict with full server response

Notes:
Check class docstirng for more info
"""
return self._processing_response(**kwargs)

async def aio_captcha_handler(self) -> dict:
"""
Async solving method

Returns:
Dict with full server response

Notes:
Check class docstirng for more info
"""
return await self._aio_processing_response()
6 changes: 6 additions & 0 deletions src/python_rucaptcha/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ class CaptchaFoxEnm(str, MyEnum):

class VKCaptchaEnm(str, MyEnum):
VKCaptchaTask = "VKCaptchaTask"
VKCaptchaImageTask = "VKCaptchaImageTask"


class TemuCaptchaEnm(str, MyEnum):
TemuCaptchaTask = "TemuCaptchaTask"


class BinanceCaptchaEnm(str, MyEnum):
BinanceTaskProxyless = "BinanceTaskProxyless"
BinanceTask = "BinanceTask"
Loading
Loading