Skip to content

Commit ba77ae8

Browse files
authored
- Added description of parameters to method documentation in solver.py file (#79)
- Updated the “see more info in the API docs” link in the README.md file - Added a description of methods supporting proxies for the solution and information about whether we have our own proxy for customers in the proxies section in the README.md file - Added extended examples amazon_waf_options.py, geetest_v4_options,.py, turnstile_options.py to examples. - Added data parameter to hcaptcha_options.py example - Changed the name of the sol=>solver variable in the example file keycaptcha_options.py - Added package description to __init__.py file Signed-off-by: Maxim S <[email protected]>
1 parent 4e770bf commit ba77ae8

File tree

8 files changed

+694
-309
lines changed

8 files changed

+694
-309
lines changed

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The easiest way to quickly integrate the 2Captcha captcha-solving service into y
3030
- [Friendly Captcha](#friendly-captcha)
3131
- [Cutcaptcha](#cutcaptcha)
3232
- [Other methods](#other-methods)
33-
- [send / getResult](#send--getresult)
33+
- [send / get_result](#send--getresult)
3434
- [balance](#balance)
3535
- [report](#report)
3636
- [Error handling](#error-handling)
@@ -80,7 +80,7 @@ solver = TwoCaptcha(**config)
8080
| pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended |
8181

8282
> **IMPORTANT:** once `callback` is defined for `TwoCaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL.
83-
To get the answer manually use [getResult method](#send--getresult)
83+
To get the answer manually use [get_result method](#send--getresult)
8484

8585
## Solve captcha
8686
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.
@@ -162,20 +162,21 @@ result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e',
162162
```
163163

164164

165-
### hCaptcha
166-
Use this method to solve the hCaptcha challenge. Returns a token to bypass the captcha.
165+
### GeeTest v4
166+
Use this method to solve GeeTest v4. Returns the response in JSON.
167167
```python
168-
result = solver.hcaptcha(sitekey='10000000-ffff-ffff-ffff-000000000001',
169-
url='https://www.site.com/page/',
168+
result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
169+
url='https://www.site.com/page/',
170170
param1=..., ...)
171171

172172
```
173173

174-
### GeeTest v4
175-
Use this method to solve GeeTest v4. Returns the response in JSON.
174+
175+
### hCaptcha
176+
Use this method to solve the hCaptcha challenge. Returns a token to bypass the captcha.
176177
```python
177-
result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
178-
url='https://www.site.com/page/',
178+
result = solver.hcaptcha(sitekey='10000000-ffff-ffff-ffff-000000000001',
179+
url='https://www.site.com/page/',
179180
param1=..., ...)
180181

181182
```
@@ -299,7 +300,7 @@ result = solver.cutcaptcha(misery_key='ad52c87af17e2ec09b8d918c9f00416b1cb8c320'
299300

300301
## Other methods
301302

302-
### send / getResult
303+
### send / get_result
303304
These methods can be used for manual captcha submission and answer polling.
304305
```python
305306
import time
@@ -347,7 +348,11 @@ except TimeoutException as e:
347348

348349
### Proxies
349350

350-
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha and geetest. The proxy will be forwarded to the API to solve the captcha.
351+
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha,
352+
keycaptcha, capy pazzle, grid, rotate, lemin, atbcaptcha, turnstile, amazon waf, mtcaptcha, friendly captcha, cutcaptcha.
353+
The proxy will be forwarded to the API to solve the captcha.
354+
355+
We have our own proxies that we can offer you. [Buy residential proxies] for avoid restrictions and blocks. [Quick start].
351356

352357
```python
353358
proxy={
@@ -377,7 +382,9 @@ async def captchaSolver(image):
377382
[2Captcha]: https://2captcha.com/
378383
[2captcha sofware catalog]: https://2captcha.com/software
379384
[pingback settings]: https://2captcha.com/setting/pingback
380-
[post options]: https://2captcha.com/2captcha-api#normal_post
385+
[post options]: https://2captcha.com/2captcha-api#solving_normal_captcha
381386
[list of supported languages]: https://2captcha.com/2captcha-api#language
382387
[examples directory]: /examples
383388
[asyncio]: https://docs.python.org/3/library/asyncio.html
389+
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
390+
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true

examples/amazon_waf_options.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22+
'defaultTimeout': 120,
23+
'recaptchaTimeout': 600,
24+
'pollingInterval': 10,
25+
}
26+
27+
solver = TwoCaptcha(**config)
28+
29+
try:
30+
result = solver.amazon_waf(sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AGIqvS8v6ScFa8ZpNRrlQgKAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMx9gxoe10Zg35PWhzAgEQgDvUtMMkqkFQByMLK2329D8iX4mjvaTuUhU70LD4vLp54v3+4K1nYY2hB+OM1hMbncnMbP63y4UOrY77jg==',
31+
iv='CgAGVTNd9JAAAAnB',
32+
context='Lte3LdSjiAN6nNcV0omaNt/ydFmd/eTwRCxYEeuW97LZe3IbAXWi4Er9CWQ3HbDgJ0KSpDgwyoskjKCK4VRQzYufPCdrfCYCveZCt9pMNoAluEtj0oix2GXOPVkw2d4bYOg3MtY5ZUHLR3L467NEInnRE99w5NOgokH5Ie7eOi5sYAqYtZrHABGEgrdAOVvU7bcwvrCERi9wB/WS75geb3oFy6z7Apue9GFa86Ld20jjgy4LWfaen+2fpfKHmCHTKVWfto17Bg+l5i0sr+uFRzpk1We64Fhh1Wl1NHF6M6dpS5s=',
33+
url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',
34+
challenge_script="https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js",
35+
captcha_script="https://41bcdd4fb3cb.610cd090.us-east-1.captcha.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/captcha.js",
36+
callback="https://mysite.com/2captcha.txt"
37+
# proxy={
38+
# 'type': 'HTTPS',
39+
# 'uri': 'login:password@IP_address:PORT'
40+
# }
41+
)
42+
43+
except Exception as e:
44+
sys.exit(e)
45+
46+
else:
47+
sys.exit('result: ' + str(result))

examples/geetest_v4_options.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import os
3+
import requests
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+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
21+
'defaultTimeout': 120,
22+
'recaptchaTimeout': 600,
23+
'pollingInterval': 10,
24+
}
25+
26+
solver = TwoCaptcha(**config)
27+
28+
try:
29+
result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
30+
url='https://2captcha.com/demo/geetest-v4',
31+
# proxy={
32+
# 'type': 'HTTPS',
33+
# 'uri': 'login:password@IP_address:PORT'
34+
# }
35+
)
36+
37+
except Exception as e:
38+
sys.exit(e)
39+
40+
else:
41+
sys.exit('result: ' + str(result))

examples/hcaptcha_options.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
solver = TwoCaptcha(**config)
2828

2929
try:
30-
result = solver.hcaptcha(sitekey='3ceb8624-1970-4e6b-91d5-70317b70b651',
31-
url='https://2captcha.com/demo/hcaptcha?difficulty=easy',
32-
# proxy={
33-
# 'type': 'HTTPS',
34-
# 'uri': 'login:password@IP_address:PORT'
35-
# }
30+
result = solver.hcaptcha(sitekey='f7de0da3-3303-44e8-ab48-fa32ff8ccc7b',
31+
url='https://2captcha.com/ru/demo/hcaptcha-invisible',
32+
# invisible=1,
33+
# data="rqdata",
34+
# useragent="",
35+
# proxy={
36+
# 'type': 'HTTPS',
37+
# 'uri': 'login:password@IP_address:PORT'
38+
# }
3639
)
3740

3841
except Exception as e:

examples/keycaptcha_options.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
import sys
2-
'../../' in sys.path or sys.path.append('../../')
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
35

46
from twocaptcha import TwoCaptcha
57

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')
615

716

8-
sol = TwoCaptcha('YOUR_API_KEY', defaultTimeout=120)
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22+
'defaultTimeout': 120,
23+
'recaptchaTimeout': 600,
24+
'pollingInterval': 10,
25+
}
926

27+
solver = TwoCaptcha(**config)
1028

1129
try:
12-
result = sol.keycaptcha(s_s_c_user_id = 10,
13-
s_s_c_session_id = '493e52c37c10c2bcdf4a00cbc9ccd1e8',
14-
s_s_c_web_server_sign = '9006dc725760858e4c0715b835472f22-pz-',
15-
s_s_c_web_server_sign2 = '2ca3abe86d90c6142d5571db98af6714',
16-
url = 'https://www.keycaptcha.ru/demo-magnetic/',
17-
proxy = {
18-
'type': 'HTTPS',
19-
'uri': 'login:password@IP_address:PORT'})
30+
result = solver.keycaptcha(s_s_c_user_id = 184015,
31+
s_s_c_session_id = 'c32c9934c68b2968bee0332b9346da42',
32+
s_s_c_web_server_sign = 'c93c8d136d5ee6ee6fe27ab2be54901d',
33+
s_s_c_web_server_sign2 = 'eec85fcfeda28bffd7764d712d4089e7',
34+
url = 'https://2captcha.com/ru/demo/keycaptcha'
35+
# proxy = {
36+
# 'type': 'HTTPS',
37+
# 'uri': 'login:password@IP_address:PORT'}
38+
)
2039

2140

2241
except Exception as e:

examples/turnstile_options.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22+
'defaultTimeout': 120,
23+
'recaptchaTimeout': 600,
24+
'pollingInterval': 10,
25+
}
26+
27+
solver = TwoCaptcha(**config)
28+
29+
try:
30+
result = solver.turnstile(sitekey='0x4AAAAAAAVrOwQWPlm3Bnr5',
31+
url='https://2captcha.com/demo/turnstile',
32+
# data="str",
33+
# pagedata="str",
34+
# action="str",
35+
# useragent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
36+
# proxy={
37+
# 'type': 'HTTPS',
38+
# 'uri': 'login:password@IP_address:PORT'
39+
# }
40+
)
41+
42+
except Exception as e:
43+
sys.exit(e)
44+
45+
else:
46+
sys.exit('result: ' + str(result))

twocaptcha/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
from .solver import (TwoCaptcha, SolverExceptions, ValidationException,
33
NetworkException, ApiException, TimeoutException)
44

5+
"""
6+
Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha,
7+
funcaptcha, geetest and solve any other captchas.
8+
9+
website 2captcha [https://2captcha.com/]
10+
11+
# License: MIT
12+
"""
13+
14+
__author__ = '2captcha'
515
__version__ = '1.2.4'

0 commit comments

Comments
 (0)