From 7d2c01ac924dea71b58dfcaaf45dd9e65807c0df Mon Sep 17 00:00:00 2001 From: Maxim S Date: Fri, 29 May 2026 14:38:33 +0200 Subject: [PATCH] added binance captcha to sync and async methods, examples, tests and to readme --- README.md | 12 +++++++ examples/async/async_binance.py | 32 ++++++++++++++++++ examples/async/async_binance_options.py | 44 +++++++++++++++++++++++++ examples/sync/binance.py | 29 ++++++++++++++++ examples/sync/binance_options.py | 42 +++++++++++++++++++++++ tests/async/test_async_binance.py | 36 ++++++++++++++++++++ tests/sync/test_binance.py | 38 +++++++++++++++++++++ twocaptcha/async_solver.py | 25 +++++++++++++- twocaptcha/solver.py | 25 ++++++++++++++ 9 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 examples/async/async_binance.py create mode 100644 examples/async/async_binance_options.py create mode 100644 examples/sync/binance.py create mode 100644 examples/sync/binance_options.py create mode 100644 tests/async/test_async_binance.py create mode 100644 tests/sync/test_binance.py diff --git a/README.md b/README.md index 2e58c39..eb5ccf1 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Examples of API requests for different captcha types are available on the [Pytho - [Temu](#temu) - [CyberSiARA](#cybersiara) - [Altcha Captcha](#altcha-Captcha) + - [Binance](#binance) - [Other methods](#other-methods) - [send / get\_result](#send--get_result) - [balance](#balance) @@ -536,6 +537,17 @@ result = solver.altcha(pageurl='https://mysite.com/page/with/altcha', # challenge_url='https://example.com/altcha-challenge',) ``` +### Binance + +[API method description.](https://2captcha.com/2captcha-api#binance) + +Use this method to solve Binance Captcha. Returns a token. +```python +result = solver.binance(sitekey='register', + pageurl='https://mysite.com/page/with/binance', + validate_id='e20c622fa9384952832fc1c2a6b75c0a',) +``` + ## Other methods ### send / get_result diff --git a/examples/async/async_binance.py b/examples/async/async_binance.py new file mode 100644 index 0000000..f1d92ff --- /dev/null +++ b/examples/async/async_binance.py @@ -0,0 +1,32 @@ +import asyncio +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import AsyncTwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + +solver = AsyncTwoCaptcha(api_key) + +async def solve_captcha(): + try: + return await solver.binance( + sitekey='register', + pageurl='https://mysite.com/page/with/binance', + validate_id='b51e733eff42458e98e0642d18842a3b', + ) + + except Exception as e: + sys.exit(e) + +if __name__ == '__main__': + result = asyncio.run(solve_captcha()) + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/async/async_binance_options.py b/examples/async/async_binance_options.py new file mode 100644 index 0000000..35938ca --- /dev/null +++ b/examples/async/async_binance_options.py @@ -0,0 +1,44 @@ +import asyncio +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) + +from twocaptcha import AsyncTwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + +config = { + 'server': '2captcha.com', # can be also set to 'rucaptcha.com' + 'apiKey': api_key, + 'softId': 123, + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = AsyncTwoCaptcha(**config) + +async def solve_captcha(): + try: + return await solver.binance( + sitekey='register', + pageurl='https://mysite.com/page/with/binance', + validate_id='ef032bbedd1940f899017b26b0499ae6', + useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + proxy={'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + ) + except Exception as e: + sys.exit(e) + +if __name__ == '__main__': + result = asyncio.run(solve_captcha()) + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/sync/binance.py b/examples/sync/binance.py new file mode 100644 index 0000000..77ca783 --- /dev/null +++ b/examples/sync/binance.py @@ -0,0 +1,29 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import TwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + +solver = TwoCaptcha(api_key) + +try: + result = solver.binance( + sitekey='register', + pageurl='https://mysite.com/page/with/binance', + validate_id='e20c622fa9384952832fc1c2a6b75c0a', + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/examples/sync/binance_options.py b/examples/sync/binance_options.py new file mode 100644 index 0000000..736092c --- /dev/null +++ b/examples/sync/binance_options.py @@ -0,0 +1,42 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) + +from twocaptcha import TwoCaptcha + +# in this example we store the API key inside environment variables that can be set like: +# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS +# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows +# you can just set the API key directly to it's value like: +# api_key="1abc234de56fab7c89012d34e56fa7b8" + +api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') + +config = { + 'server': '2captcha.com', # can be also set to 'rucaptcha.com' + 'apiKey': api_key, + 'softId': 123, + 'defaultTimeout': 120, + 'recaptchaTimeout': 600, + 'pollingInterval': 10, + } + +solver = TwoCaptcha(**config) + +try: + result = solver.binance( + sitekey='register', + pageurl='https://mysite.com/page/with/binance', + validate_id='e20c622fa9384952832fc1c2a6b75c0a', + useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/148.0.0.0 Safari/537.36", + proxy={'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + ) + +except Exception as e: + sys.exit(e) + +else: + sys.exit('result: ' + str(result)) \ No newline at end of file diff --git a/tests/async/test_async_binance.py b/tests/async/test_async_binance.py new file mode 100644 index 0000000..111bd30 --- /dev/null +++ b/tests/async/test_async_binance.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract_async import AsyncAbstractTest +except ImportError: + from abstract_async import AsyncAbstractTest + + +class AsyncBinance(AsyncAbstractTest): + def test_all_params(self): + params = { + 'sitekey': 'register', + 'pageurl': 'https://mysite.com/page/with/binance', + 'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a', + 'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', + 'proxy': {'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + } + + sends = { + 'method': 'binance', + 'sitekey': 'register', + 'pageurl': 'https://mysite.com/page/with/binance', + 'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a', + 'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', + 'proxytype': 'HTTP', + 'proxy': 'login:password@IP_address:PORT' + } + + self.send_return(sends, self.solver.binance, **params) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/sync/test_binance.py b/tests/sync/test_binance.py new file mode 100644 index 0000000..2abf352 --- /dev/null +++ b/tests/sync/test_binance.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import unittest + +try: + from .abstract import AbstractTest +except ImportError: + from abstract import AbstractTest + + +class CaptchaBinance(AbstractTest): + + def test_all_params(self): + params = { + 'sitekey': 'register', + 'pageurl': 'https://mysite.com/page/with/binance', + 'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a', + 'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', + 'proxy': {'type': 'HTTP', + 'uri': 'login:password@IP_address:PORT'} + } + + sends = { + 'method': 'binance', + 'sitekey': 'register', + 'pageurl': 'https://mysite.com/page/with/binance', + 'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a', + 'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36', + 'proxytype': 'HTTP', + 'proxy': 'login:password@IP_address:PORT' + } + + return self.send_return(sends, self.solver.binance, **params) + + +if __name__ == '__main__': + unittest.main() + diff --git a/twocaptcha/async_solver.py b/twocaptcha/async_solver.py index b7d291a..4735a6a 100644 --- a/twocaptcha/async_solver.py +++ b/twocaptcha/async_solver.py @@ -1013,7 +1013,6 @@ async def altcha(self, pageurl, **kwargs): At least one of the parameters 'challenge_url', 'challenge_json' must be passed. proxy : dict, optional {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. - ''' result = self.solve(pageurl=pageurl, @@ -1022,6 +1021,30 @@ async def altcha(self, pageurl, **kwargs): return await result + async def binance(self, pageurl, sitekey, validate_id, **kwargs): + '''Wrapper for solving Binance captcha. + + Parameters + __________ + pageurl : str + Full URL of the page where you solve the captcha. + sitekey : str + Value of 'bizId', 'bizType', or 'bizCode' from page requests. + validate_id : str + Dynamic value of 'validateId', 'securityId', or 'securityCheckResponseValidateId'. + useragent : str, optional + Browser User-Agent. We recommend sending a valid Windows browser string. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + result = self.solve(method="binance", + pageurl=pageurl, + sitekey=sitekey, + validate_id=validate_id, + **kwargs) + + return await result + async def solve(self, timeout=0, polling_interval=0, **kwargs): '''Sends captcha, receives result. diff --git a/twocaptcha/solver.py b/twocaptcha/solver.py index afa2253..a0857fe 100755 --- a/twocaptcha/solver.py +++ b/twocaptcha/solver.py @@ -1156,6 +1156,31 @@ def altcha(self, pageurl, **kwargs): **kwargs) return result + + def binance(self, pageurl, sitekey, validate_id, **kwargs): + '''Wrapper for solving Binance captcha. + + Parameters + __________ + pageurl : str + Full URL of the page where you solve the captcha. + sitekey : str + Value of 'bizId', 'bizType', or 'bizCode' from page requests. + validate_id : str + Dynamic value of 'validateId', 'securityId', or 'securityCheckResponseValidateId'. + useragent : str, optional + Browser User-Agent. We recommend sending a valid Windows browser string. + proxy : dict, optional + {'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}. + ''' + result = self.solve( + method="binance", + pageurl=pageurl, + sitekey=sitekey, + validate_id=validate_id, + **kwargs) + + return result def solve(self, timeout=0, polling_interval=0, **kwargs):