Skip to main content

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


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)

Uploaded Source

Built Distribution

2captcha_python-1.0.0-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page