Skip to content

Commit 1b2782f

Browse files
iamarkadiypolukhin2captcha
andauthored
Add methods geetest_v4, lemin, turnstile and amazon_waf to TwoCaptcha class. (#51)
* Add methods geetest_v4, lemin, turnstile and amazon_waf * Update methods geetest_v4, lemin, turnstile, amazon_waf. Add examples in README * use url instead of pageurl * add geetest v4 example * add geetest_v4 test * add lemin example * use the save env variable in examples * add lemin test * add turnstile example * add turnstile test * added amazon_waf example * added amazon_waf test --------- Co-authored-by: 2captcha <support@2captcha.com>
1 parent 11d2193 commit 1b2782f

10 files changed

Lines changed: 445 additions & 40 deletions

File tree

README.md

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
# Python Module for 2Captcha API
22
The easiest way to quickly integrate [2Captcha] captcha solving service into your code to automate solving of any types of captcha.
33

4-
- [Installation](#installation)
5-
- [Configuration](#configuration)
6-
- [Solve captcha](#solve-captcha)
7-
- [Normal Captcha](#normal-captcha)
8-
- [Text](#text-captcha)
9-
- [ReCaptcha v2](#recaptcha-v2)
10-
- [ReCaptcha v3](#recaptcha-v3)
11-
- [FunCaptcha](#funcaptcha)
12-
- [GeeTest](#geetest)
13-
- [hCaptcha](#hcaptcha)
14-
- [KeyCaptcha](#keycaptcha)
15-
- [Capy](#capy)
16-
- [Grid (ReCaptcha V2 Old Method)](#grid)
17-
- [Canvas](#canvas)
18-
- [ClickCaptcha](#clickcaptcha)
19-
- [Rotate](#rotate)
20-
- [Other methods](#other-methods)
21-
- [send / getResult](#send--getresult)
22-
- [balance](#balance)
23-
- [report](#report)
24-
- [Error handling](#error-handling)
4+
- [Python Module for 2Captcha API](#python-module-for-2captcha-api)
5+
- [Installation](#installation)
6+
- [Configuration](#configuration)
7+
- [TwoCaptcha instance options](#twocaptcha-instance-options)
8+
- [Solve captcha](#solve-captcha)
9+
- [Captcha options](#captcha-options)
10+
- [Normal Captcha](#normal-captcha)
11+
- [Text Captcha](#text-captcha)
12+
- [ReCaptcha v2](#recaptcha-v2)
13+
- [ReCaptcha v3](#recaptcha-v3)
14+
- [FunCaptcha](#funcaptcha)
15+
- [GeeTest](#geetest)
16+
- [hCaptcha](#hcaptcha)
17+
- [GeeTest v4](#geetest-v4)
18+
- [Lemin Cropped Captcha](#lemin-cropped-captcha)
19+
- [Cloudflare Turnstile](#cloudflare-turnstile)
20+
- [Amazon WAF](#amazon-waf)
21+
- [KeyCaptcha](#keycaptcha)
22+
- [Capy](#capy)
23+
- [Grid](#grid)
24+
- [Canvas](#canvas)
25+
- [ClickCaptcha](#clickcaptcha)
26+
- [Rotate](#rotate)
27+
- [Other methods](#other-methods)
28+
- [send / getResult](#send--getresult)
29+
- [balance](#balance)
30+
- [report](#report)
31+
- [Error handling](#error-handling)
32+
- [Proxies](#proxies)
33+
- [Async calls](#async-calls)
2534

2635
## Installation
2736

@@ -56,14 +65,14 @@ solver = TwoCaptcha(**config)
5665

5766
### TwoCaptcha instance options
5867

59-
|Option|Default value|Description|
60-
|---|---|---|
61-
|server|`2captcha.com`|API server. You can set it to `rucaptcha.com` if your account is registered there|
62-
|softId|-|your software ID obtained after publishing in [2captcha sofware catalog]|
63-
|callback|-|URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account|
64-
|defaultTimeout|120|Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from `res.php` API endpoint|
65-
|recaptchaTimeout|600|Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint|
66-
|pollingInterval|10|Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended|
68+
| Option | Default value | Description |
69+
| ---------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
70+
| server | `2captcha.com` | API server. You can set it to `rucaptcha.com` if your account is registered there |
71+
| softId | - | your software ID obtained after publishing in [2captcha sofware catalog] |
72+
| callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account |
73+
| defaultTimeout | 120 | Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from `res.php` API endpoint |
74+
| recaptchaTimeout | 600 | Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint |
75+
| pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended |
6776

6877
> **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.
6978
To get the answer manually use [getResult method](#send--getresult)
@@ -72,17 +81,17 @@ To get the answer manually use [getResult method](#send--getresult)
7281
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.
7382

7483
### Captcha options
75-
|Option|Default Value|Description|
76-
|---|---|---|
77-
|numeric|0|Defines if captcha contains numeric or other symbols [see more info in the API docs][post options]|
78-
|minLength|0|minimal answer lenght|
79-
|maxLength|0|maximum answer length|
80-
|phrase|0|defines if the answer contains multiple words or not|
81-
|caseSensitive|0|defines if the answer is case sensitive|
82-
|calc|0|defines captcha requires calculation|
83-
|lang|-|defines the captcha language, see the [list of supported languages] |
84-
|hintImg|-|an image with hint shown to workers with the captcha|
85-
|hintText|-|hint or task text shown to workers with the captcha|
84+
| Option | Default Value | Description |
85+
| ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
86+
| numeric | 0 | Defines if captcha contains numeric or other symbols [see more info in the API docs][post options] |
87+
| minLength | 0 | minimal answer lenght |
88+
| maxLength | 0 | maximum answer length |
89+
| phrase | 0 | defines if the answer contains multiple words or not |
90+
| caseSensitive | 0 | defines if the answer is case sensitive |
91+
| calc | 0 | defines captcha requires calculation |
92+
| lang | - | defines the captcha language, see the [list of supported languages] |
93+
| hintImg | - | an image with hint shown to workers with the captcha |
94+
| hintText | - | hint or task text shown to workers with the captcha |
8695

8796
Below you can find basic examples for every captcha type. Check out [examples directory] to find more examples with all available options.
8897

@@ -147,6 +156,48 @@ result = solver.hcaptcha(sitekey='10000000-ffff-ffff-ffff-000000000001',
147156

148157
```
149158

159+
### GeeTest v4
160+
Use this method to solve GeeTest v4. Returns the response in JSON.
161+
```python
162+
result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
163+
url='https://www.site.com/page/',
164+
param1=..., ...)
165+
166+
```
167+
168+
169+
### Lemin Cropped Captcha
170+
Use this method to solve hCaptcha challenge. Returns JSON with answer containing the following values: answer, challenge_id.
171+
```python
172+
result = solver.lemin(captcha_id='CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
173+
div_id='lemin-cropped-captcha',
174+
url='https://www.site.com/page/',
175+
param1=..., ...)
176+
177+
```
178+
179+
180+
### Cloudflare Turnstile
181+
Use this method to solve Cloudflare Turnstile. Returns JSON with the token.
182+
```python
183+
result = solver.turnstile(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',
184+
url='http://mysite.com/',
185+
param1=..., ...)
186+
187+
```
188+
189+
### Amazon WAF
190+
Use this method to solve Amazon WAF Captcha also known as AWS WAF Captcha is a part of Intelligent threat mitigation for Amazon AWS. Returns JSON with the token.
191+
```python
192+
result = solver.amazon_waf(sitekey='0x1AAAAAAAAkg0s2VIOD34y5',
193+
iv='CgAHbCe2GgAAAAAj',
194+
context='9BUgmlm48F92WUoqv97a49ZuEJJ50TCk9MVr3C7WMtQ0X6flVbufM4n8mjFLmbLVAPgaQ1Jydeaja94iAS49ljb+sUNLoukWedAQZKrlY4RdbOOzvcFqmD/ZepQFS9N5w15Exr4VwnVq+HIxTsDJwRviElWCdzKDebN/mk8/eX2n7qJi5G3Riq0tdQw9+C4diFZU5E97RSeahejOAAJTDqduqW6uLw9NsjJBkDRBlRjxjn5CaMMo5pYOxYbGrM8Un1JH5DMOLeXbq1xWbC17YSEoM1cRFfTgOoc+VpCe36Ai9Kc='
195+
url='https://non-existent-example.execute-api.us-east-1.amazonaws.com/latest'
196+
param1=..., ...)
197+
198+
```
199+
200+
150201
### KeyCaptcha
151202
Token-based method to solve KeyCaptcha.
152203
```python

examples/amazon_waf.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.amazon_waf(
20+
sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
21+
iv='CgAAYDJb9CAAACAq',
22+
context='wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ=',
23+
url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',
24+
)
25+
26+
except Exception as e:
27+
sys.exit(e)
28+
29+
else:
30+
sys.exit('result: ' + str(result))

examples/geetest_v4.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.geetest_v4(captcha_id='e392e1d7fd421dc63325744d5a2b9c73',
20+
url='https://2captcha.com/demo/geetest-v4')
21+
22+
except Exception as e:
23+
sys.exit(e)
24+
25+
else:
26+
sys.exit('result: ' + str(result))

examples/lemin.py

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

examples/turnstile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.turnstile(
20+
sitekey='0x4AAAAAAAC3DHQFLr1GavRN',
21+
url='https://2captcha.com/demo/turnstile',
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

tests/test_amazon_waf.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
class AmazonWAFTest(AbstractTest):
11+
12+
13+
def test_all_params(self):
14+
15+
16+
params = {
17+
'sitekey' : 'AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52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=',
28+
'pageurl' : 'https://www.site.com/page/',
29+
}
30+
31+
return self.send_return(sends, self.solver.amazon_waf, **params)
32+
33+
34+
if __name__ == '__main__':
35+
36+
unittest.main()
37+
38+
39+
# sitekey='AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AFsClhVgr5q0UFRdXhhHEwiAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMLMbH8d6uQSrYTraoAgEQgDvtSNxdEyG7Zu393cHyPdWNCZgeIB52+W7fCTI8U5z15z1NdPUdnB1ZHoK7ewpwoSMm5mzkJJld0cnvGw==',
40+
# iv='CgAAYDJb9CAAACAq',
41+
# context='wCho9T9OcETTT8fu1k6+rszr5aGt4eLd+K3mHpV8VbSkjAWJGJx/iQ16RKDCTQBtU5OSeE+SQqoS5iTzhgGtvwgmBbr7X/I+aXaNfb2JRZ8eJ7CnQpM9QRwnv7vGgrGRBGhkh/jaVYmXdy0j0x21s3dCBlA4VN3naDHIweZqkyhXqJBNI1Ep8OMSnhXtPebboB117aBW4IU4XEOii8EE1G4Z7ndWhrNVVXYYwVoxfnSqfYX//CJir6dZfLMbCt5t7NnO8yjsx/YHGVXFVBt2Zrj0ZTxowoYbHU/BKyFaXgUj+ZQ=',
42+
# url='https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest',

tests/test_geetest_v4.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
12+
class GeeTest_V4(AbstractTest):
13+
14+
15+
def test_all_params(self):
16+
17+
18+
params = {
19+
'captcha_id': 'e392e1d7fd421dc63325744d5a2b9c73',
20+
'url' : 'https://2captcha.com/demo/geetest-v4', }
21+
22+
sends = {
23+
'method' : 'geetest_v4',
24+
'captcha_id' : 'e392e1d7fd421dc63325744d5a2b9c73',
25+
'pageurl' : 'https://2captcha.com/demo/geetest-v4',
26+
}
27+
28+
return self.send_return(sends, self.solver.geetest_v4, **params)
29+
30+
31+
if __name__ == '__main__':
32+
33+
unittest.main()
34+

tests/test_lemin.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
12+
class LeminTest(AbstractTest):
13+
14+
15+
def test_all_params(self):
16+
17+
18+
params = {
19+
'captcha_id' : 'CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
20+
'div_id' : 'lemin-cropped-captcha',
21+
'api_server' : 'https://api.leminnow.com/',
22+
'url' : 'http://mysite.com/',
23+
}
24+
25+
sends = {
26+
'method' : 'lemin',
27+
'captcha_id' : 'CROPPED_1abcd2f_a1234b567c890d12ef3a456bc78d901d',
28+
'div_id' : 'lemin-cropped-captcha',
29+
'api_server' : 'https://api.leminnow.com/',
30+
'pageurl' : 'http://mysite.com/',
31+
}
32+
33+
return self.send_return(sends, self.solver.lemin, **params)
34+
35+
36+
37+
38+
39+
if __name__ == '__main__':
40+
41+
unittest.main()
42+

0 commit comments

Comments
 (0)