Skip to content

Commit 7d2c01a

Browse files
committed
added binance captcha to sync and async methods, examples, tests and to readme
1 parent 59a4f3a commit 7d2c01a

9 files changed

Lines changed: 282 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Examples of API requests for different captcha types are available on the [Pytho
4949
- [Temu](#temu)
5050
- [CyberSiARA](#cybersiara)
5151
- [Altcha Captcha](#altcha-Captcha)
52+
- [Binance](#binance)
5253
- [Other methods](#other-methods)
5354
- [send / get\_result](#send--get_result)
5455
- [balance](#balance)
@@ -536,6 +537,17 @@ result = solver.altcha(pageurl='https://mysite.com/page/with/altcha',
536537
# challenge_url='https://example.com/altcha-challenge',)
537538
```
538539

540+
### Binance
541+
542+
<sup>[API method description.](https://2captcha.com/2captcha-api#binance)</sup>
543+
544+
Use this method to solve Binance Captcha. Returns a token.
545+
```python
546+
result = solver.binance(sitekey='register',
547+
pageurl='https://mysite.com/page/with/binance',
548+
validate_id='e20c622fa9384952832fc1c2a6b75c0a',)
549+
```
550+
539551
## Other methods
540552

541553
### send / get_result

examples/async/async_binance.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
solver = AsyncTwoCaptcha(api_key)
18+
19+
async def solve_captcha():
20+
try:
21+
return await solver.binance(
22+
sitekey='register',
23+
pageurl='https://mysite.com/page/with/binance',
24+
validate_id='b51e733eff42458e98e0642d18842a3b',
25+
)
26+
27+
except Exception as e:
28+
sys.exit(e)
29+
30+
if __name__ == '__main__':
31+
result = asyncio.run(solve_captcha())
32+
sys.exit('result: ' + str(result))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import asyncio
2+
import sys
3+
import os
4+
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
6+
7+
from twocaptcha import AsyncTwoCaptcha
8+
9+
# in this example we store the API key inside environment variables that can be set like:
10+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
11+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
12+
# you can just set the API key directly to it's value like:
13+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
14+
15+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
16+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = AsyncTwoCaptcha(**config)
27+
28+
async def solve_captcha():
29+
try:
30+
return await solver.binance(
31+
sitekey='register',
32+
pageurl='https://mysite.com/page/with/binance',
33+
validate_id='ef032bbedd1940f899017b26b0499ae6',
34+
useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
35+
"Chrome/148.0.0.0 Safari/537.36",
36+
proxy={'type': 'HTTP',
37+
'uri': 'login:password@IP_address:PORT'}
38+
)
39+
except Exception as e:
40+
sys.exit(e)
41+
42+
if __name__ == '__main__':
43+
result = asyncio.run(solve_captcha())
44+
sys.exit('result: ' + str(result))

examples/sync/binance.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.binance(
20+
sitekey='register',
21+
pageurl='https://mysite.com/page/with/binance',
22+
validate_id='e20c622fa9384952832fc1c2a6b75c0a',
23+
)
24+
25+
except Exception as e:
26+
sys.exit(e)
27+
28+
else:
29+
sys.exit('result: ' + str(result))

examples/sync/binance_options.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
config = {
17+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
18+
'apiKey': api_key,
19+
'softId': 123,
20+
'defaultTimeout': 120,
21+
'recaptchaTimeout': 600,
22+
'pollingInterval': 10,
23+
}
24+
25+
solver = TwoCaptcha(**config)
26+
27+
try:
28+
result = solver.binance(
29+
sitekey='register',
30+
pageurl='https://mysite.com/page/with/binance',
31+
validate_id='e20c622fa9384952832fc1c2a6b75c0a',
32+
useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
33+
"Chrome/148.0.0.0 Safari/537.36",
34+
proxy={'type': 'HTTP',
35+
'uri': 'login:password@IP_address:PORT'}
36+
)
37+
38+
except Exception as e:
39+
sys.exit(e)
40+
41+
else:
42+
sys.exit('result: ' + str(result))

tests/async/test_async_binance.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract_async import AsyncAbstractTest
7+
except ImportError:
8+
from abstract_async import AsyncAbstractTest
9+
10+
11+
class AsyncBinance(AsyncAbstractTest):
12+
def test_all_params(self):
13+
params = {
14+
'sitekey': 'register',
15+
'pageurl': 'https://mysite.com/page/with/binance',
16+
'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a',
17+
'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',
18+
'proxy': {'type': 'HTTP',
19+
'uri': 'login:password@IP_address:PORT'}
20+
}
21+
22+
sends = {
23+
'method': 'binance',
24+
'sitekey': 'register',
25+
'pageurl': 'https://mysite.com/page/with/binance',
26+
'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a',
27+
'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',
28+
'proxytype': 'HTTP',
29+
'proxy': 'login:password@IP_address:PORT'
30+
}
31+
32+
self.send_return(sends, self.solver.binance, **params)
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main()

tests/sync/test_binance.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class CaptchaBinance(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
'sitekey': 'register',
16+
'pageurl': 'https://mysite.com/page/with/binance',
17+
'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a',
18+
'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',
19+
'proxy': {'type': 'HTTP',
20+
'uri': 'login:password@IP_address:PORT'}
21+
}
22+
23+
sends = {
24+
'method': 'binance',
25+
'sitekey': 'register',
26+
'pageurl': 'https://mysite.com/page/with/binance',
27+
'validate_id': 'e20c622fa9384952832fc1c2a6b75c0a',
28+
'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',
29+
'proxytype': 'HTTP',
30+
'proxy': 'login:password@IP_address:PORT'
31+
}
32+
33+
return self.send_return(sends, self.solver.binance, **params)
34+
35+
36+
if __name__ == '__main__':
37+
unittest.main()
38+

twocaptcha/async_solver.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,6 @@ async def altcha(self, pageurl, **kwargs):
10131013
At least one of the parameters 'challenge_url', 'challenge_json' must be passed.
10141014
proxy : dict, optional
10151015
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1016-
10171016
'''
10181017

10191018
result = self.solve(pageurl=pageurl,
@@ -1022,6 +1021,30 @@ async def altcha(self, pageurl, **kwargs):
10221021

10231022
return await result
10241023

1024+
async def binance(self, pageurl, sitekey, validate_id, **kwargs):
1025+
'''Wrapper for solving Binance captcha.
1026+
1027+
Parameters
1028+
__________
1029+
pageurl : str
1030+
Full URL of the page where you solve the captcha.
1031+
sitekey : str
1032+
Value of 'bizId', 'bizType', or 'bizCode' from page requests.
1033+
validate_id : str
1034+
Dynamic value of 'validateId', 'securityId', or 'securityCheckResponseValidateId'.
1035+
useragent : str, optional
1036+
Browser User-Agent. We recommend sending a valid Windows browser string.
1037+
proxy : dict, optional
1038+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1039+
'''
1040+
result = self.solve(method="binance",
1041+
pageurl=pageurl,
1042+
sitekey=sitekey,
1043+
validate_id=validate_id,
1044+
**kwargs)
1045+
1046+
return await result
1047+
10251048
async def solve(self, timeout=0, polling_interval=0, **kwargs):
10261049
'''Sends captcha, receives result.
10271050

twocaptcha/solver.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,31 @@ def altcha(self, pageurl, **kwargs):
11561156
**kwargs)
11571157

11581158
return result
1159+
1160+
def binance(self, pageurl, sitekey, validate_id, **kwargs):
1161+
'''Wrapper for solving Binance captcha.
1162+
1163+
Parameters
1164+
__________
1165+
pageurl : str
1166+
Full URL of the page where you solve the captcha.
1167+
sitekey : str
1168+
Value of 'bizId', 'bizType', or 'bizCode' from page requests.
1169+
validate_id : str
1170+
Dynamic value of 'validateId', 'securityId', or 'securityCheckResponseValidateId'.
1171+
useragent : str, optional
1172+
Browser User-Agent. We recommend sending a valid Windows browser string.
1173+
proxy : dict, optional
1174+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
1175+
'''
1176+
result = self.solve(
1177+
method="binance",
1178+
pageurl=pageurl,
1179+
sitekey=sitekey,
1180+
validate_id=validate_id,
1181+
**kwargs)
1182+
1183+
return result
11591184

11601185

11611186
def solve(self, timeout=0, polling_interval=0, **kwargs):

0 commit comments

Comments
 (0)