This library implements a simple to use wrapper around the 2Captcha.com API.
pip install twocaptchaapi
git clone https://github.com/athre0z/twocaptcha-api.git cd twocaptcha-api python setup.py install
Initializing the API
from twocaptchaapi import TwoCaptchaApi api = TwoCaptchaApi('<API KEY>')
Solving a captcha blocking
with open('/my/captcha/path.png', 'rb') as captcha_file: captcha = api.solve(captcha_file) print(captcha.await_result())
Waits until the captcha is either solved or an error occurred (indicated through an exception).
Solve captcha "non-blocking"
captcha = api.solve(captcha_file) print(captcha.try_get_result())
If already available, prints the captcha text, else None. Please note that while this code doesn't repeatedly ask the API if the captcha was solved, the HTTP request is still sent synchronously, so this method isn't really non-blocking.
Reporting a bad captcha
result = captcha.await_result() if use_captcha_code(result) == 'failed': captcha.report_bad()
Query account balance
This library was successfully tested on Python 2.7 and 3.5. Python versions < 2.7 are not officially supported.