Unicaps
Unicaps is a unified Python API for CAPTCHA solving services.
⚠ PLEASE NOTE
⚠ A solving service API key is required to use this package!
⚠ The list of the supported services you can find in the table below.
Key Features
- A unified Python interface that is independent of the service used
- Uses native service protocol/endpoints (eg, no needs in patching hosts file)
- Supports 10 types of CAPTCHAs
- Supports 5 CAPTCHA solving services (3 more would be added soon)
- Written Pythonic way and is intended for humans
Installation
pip install unicaps
Simple Usage Example
>>> from unicaps import CaptchaSolver, CaptchaSolvingService
>>> solver = CaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
>>> solver.get_balance()
2.84161
>>> solved = solver.solve_image_captcha(open("captcha.jpg", "rb"), is_phrase=False, is_case_sensitive=True)
>>> solved.solution.text
'w93Bx'
>>> solved.cost
0.00078
>>> solved.report_good()
True
Supported CAPTCHAs / Services
Image CAPTCHA
Text CAPTCHA
What is this?
Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification.
For example: "If tomorrow is Saturday, what day is today?".
reCAPTCHA v2
1 Support of solving reCAPTCHA on Google services (e.g. Google Search)
2 Support of solving via proxy server
3 Support of passing custom cookies
4 Support of passing custom User-Agent header
reCAPTCHA v3
FunCaptcha (Arkose Labs)
KeyCAPTCHA
Geetest
hCaptcha
Capy
TikTok CAPTCHA
Supported Proxy types
How to...
Common
Get balance
from unicaps import CaptchaSolver, CaptchaSolvingService
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
balance = solver.get_balance()
Get service status (is the service is up?)
from unicaps import CaptchaSolver, CaptchaSolvingService
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# get status of the service (True - everything is Okay, False - the service is down)
status = solver.get_status()
Get technical details after solving
from unicaps import CaptchaSolver, CaptchaSolvingService
# init captcha solver and solve the captcha
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
solved = solver.solve_...(...)
# get cost of the solving
cost = solved.cost
# get cookies (if any)
cookies = solved.cookies
# report good captcha
solved.report_good()
# report bad captcha
solved.report_bad()
# get solving start time
start_time = solved.start_time
# get solving end time
end_time = solved.end_time
Solving
Image CAPTCHA
import pathlib
from unicaps import CaptchaSolver, CaptchaSolvingService
from unicaps.common import CaptchaCharType, CaptchaAlphabet
# get image file
image_file = pathlib.Path(r'/tmp/captcha.png')
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_image_captcha(
image=image_file,
char_type=CaptchaCharType.ALPHA,
is_phrase=False,
is_case_sensitive=True,
is_math=False,
min_len=4,
max_len=6,
alphabet=CaptchaAlphabet.LATIN,
comment='Type RED letters only'
)
# get response token
token = solved.solution.text
reCAPTCHA v2
from unicaps import CaptchaSolver, CaptchaSolvingService
# get page URL and site_key from your page
page_url = ...
site_key = ...
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_recaptcha_v2(
site_key=site_key,
page_url=page_url
)
# get response token
token = solved.solution.token
reCAPTCHA v2 Invisible
from unicaps import CaptchaSolver, CaptchaSolvingService
# get page url and site_key from your page
page_url = ...
site_key = ...
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_recaptcha_v2(
site_key=site_key,
page_url=page_url,
is_invisible=True
)
# get response token
token = solved.solution.token
reCAPTCHA v2 Enterprise
from unicaps import CaptchaSolver, CaptchaSolvingService
# get page URL, site_key and data_s from your page
page_url = ...
site_key = ...
data_s = ...
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_recaptcha_v2(
site_key=site_key,
page_url=page_url,
data_s=data_s,
is_enterprise=True
)
# get response token
token = solved.solution.token
reCAPTCHA v3
from unicaps import CaptchaSolver, CaptchaSolvingService
# get page URL, site_key and action from your page
page_url = ...
site_key = ...
action = ...
min_score = 0.7
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_recaptcha_v3(
site_key=site_key,
page_url=page_url,
action=action,
min_score=min_score
)
# get response token
token = solved.solution.token
hCaptcha
from unicaps import CaptchaSolver, CaptchaSolvingService
# get page URL and site_key from your page
page_url = ...
site_key = ...
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_hcaptcha(
site_key=site_key,
page_url=page_url
)
# get response token
token = solved.solution.token
Error handling
Exceptions
from unicaps import CaptchaSolver, CaptchaSolvingService, exceptions
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
try:
solved = solver.solve_recaptcha_v2(
site_key=site_key,
page_url=page_url
)
except exceptions.AccessDeniedError: # wrong API key or the current IP is banned
pass
except exceptions.LowBalanceError: # low balance
pass
except exceptions.ServiceTooBusy: # no available slots to solve CAPTCHA
pass
except exceptions.SolutionWaitTimeout: # haven't received a solution within N minutes
pass
except exceptions.TooManyRequestsError: # request limit exceeded
pass
except exceptions.BadInputDataError: # bad CAPTCHA data (bad image, wrong URL, etc.)
pass
except exceptions.UnableToSolveError: # CAPTCHA unsolvable
pass
except exceptions.ProxyError: # bad proxy
pass
except exceptions.NetworkError: # network connection error
pass
else:
# get response token
token = solved.solution.token
Proxy
Add proxy, cookies and User-Agent
from unicaps import CaptchaSolver, CaptchaSolvingService
from unicaps.proxy import ProxyServer
# get page URL and site_key from your page
PAGE_URL = ...
SITE_KEY = ...
PROXY = 'http://user:password@domain.com:8080'
USER_AGENT = '<USER AGENT STRING>'
COOKIES = {'name': 'value', ...}
# init captcha solver
solver = CaptchaSolver(CaptchaSolvingService.ANTI_CAPTCHA, "PLACE YOUR API KEY HERE")
# solve CAPTCHA
solved = solver.solve_recaptcha_v2(
site_key=site_key,
page_url=page_url,
proxy=ProxyServer(PROXY),
user_agent=USER_AGENT,
cookies=COOKIES
)
# get response token
token = solved.solution.token
Code examples
Examples