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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -536,6 +537,17 @@ result = solver.altcha(pageurl='https://mysite.com/page/with/altcha',
# challenge_url='https://example.com/altcha-challenge',)
```

### Binance

<sup>[API method description.](https://2captcha.com/2captcha-api#binance)</sup>

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
Expand Down
32 changes: 32 additions & 0 deletions examples/async/async_binance.py
Original file line number Diff line number Diff line change
@@ -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))
44 changes: 44 additions & 0 deletions examples/async/async_binance_options.py
Original file line number Diff line number Diff line change
@@ -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))
29 changes: 29 additions & 0 deletions examples/sync/binance.py
Original file line number Diff line number Diff line change
@@ -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))
42 changes: 42 additions & 0 deletions examples/sync/binance_options.py
Original file line number Diff line number Diff line change
@@ -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))
36 changes: 36 additions & 0 deletions tests/async/test_async_binance.py
Original file line number Diff line number Diff line change
@@ -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()
38 changes: 38 additions & 0 deletions tests/sync/test_binance.py
Original file line number Diff line number Diff line change
@@ -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()

25 changes: 24 additions & 1 deletion twocaptcha/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Expand Down
25 changes: 25 additions & 0 deletions twocaptcha/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down