Python module for easy integration with 2Captcha API
Project description
Installation
This package can be installed like this:
pip3 install 2captcha-python
Configuration
TwoCaptcha instance can be created like this:
from twocaptcha import TwoCaptcha
solver = TwoCaptcha('YOUR_API_KEY')
Also there are few options that can be configured:
config = {
'apiKey': 'YOUR_API_KEY',
'softId': 123,
'callback': 'https://your.site/result-receiver',
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
}
solver = TwoCaptcha(**config)
Solve captcha
Below shown only base examples for every captcha type. Check out examples directory to find more examples with all available options.
Normal Captcha
result = solver.normal('path/to/captcha.jpg', param1=..., ...)
Text Captcha
result = solver.text('If tomorrow is Saturday, what day is today?', param1=..., ...)
ReCaptcha v2
result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
url='https://mysite.com/page/with/recaptcha’,
param1=..., ...)
ReCaptcha v3
result = solver.recaptcha(sitekey=’6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
url='https://mysite.com/page/with/recaptcha',
version='v3',
param1=..., ...)
FunCaptcha
result = solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
url='https://mysite.com/page/with/funcaptcha',
param1=..., ...)
GeeTest
result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e',
challenge='12345678abc90123d45678ef90123a456b',
url='https://www.site.com/page/',
param1=..., ...)
hCaptcha
result = solver.funcaptcha(sitekey='f1ab2cdefa3456789012345b6c78d90e',
challenge='12345678abc90123d45678ef90123a456b',
url='https://www.site.com/page/',
param1=..., ...)
KeyCaptcha
result = solver.keycaptcha(s_s_c_user_id=10,
s_s_c_session_id='493e52c37c10c2bcdf4a00cbc9ccd1e8',
s_s_c_web_server_sign='9006dc725760858e4c0715b835472f22-pz-',
s_s_c_web_server_sign2='2ca3abe86d90c6142d5571db98af6714',
url='https://www.keycaptcha.ru/demo-magnetic/',
param1=..., ...)
Capy
result = solver.capy(sitekey='PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
url='http://mysite.com/',
param1=..., ...)
Grid
result = solver.grid('path/to/captcha.jpg', param1=..., ...)
Canvas
result = solver.canvas('path/to/captcha.jpg', param1=..., ...)
ClickCaptcha
result = solver.coordinates('path/to/captcha.jpg', param1=..., ...)
Rotate
result = solver.rotate(['path/to/captcha1.jpg', 'path/to/captcha2.jpg', ...], param1=..., ...)
Other methods
send / getResult
import time
. . . . .
id = solver.send(file='path/to/captcha.jpg')
time.sleep(20)
code = solver.getResult(id)
balance
balance = solver.balance()
report
solver.report(id, True) # captcha solved correctly
solver.report(id, False) # captcha solved incorrectly
Error handling
Try:
result = solver.text('If tomorrow is Saturday, what day is today?')
Except ValidationException as e:
# invalid parameters passed
print(e)
Except NetworkException as e:
# network error occurred
print(e)
Except ApiException as e:
# api respond with error
print(e)
Except TimeoutException as e:
# captcha is not solved so far
print(e)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
2captcha-python-1.0.0.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for 2captcha_python-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 270649d1c2af6901667b93e5c2710dd8296df9c9644cb6cfe15ebc926b984a62 |
|
MD5 | 50a90ad693608a9beb71a48b24770679 |
|
BLAKE2b-256 | 5df64270fa9065265995b0ee241b622afd53b7eab84dba52f3e99b8d8b3d4e77 |