Python module for easy integration with 2Captcha API service to solve various types of captchas including reCAPTCHA, FunCaptcha, GeeTest, and many others
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Methods for solving interactive captcha challenges including reCAPTCHA v2/v3, FunCaptcha, GeeTest, hCaptcha, and other challenge-response systems that require browser interaction.
Solves Google reCAPTCHA v2, v3, and Enterprise versions including invisible reCAPTCHA variants.
def recaptcha(self, sitekey, url, version='v2',
enterprise=0, **kwargs):
"""
Solve reCAPTCHA v2/v3 and Enterprise.
Parameters:
- sitekey (str): Value of sitekey parameter from the page (required)
- url (str): Full URL where reCAPTCHA is located (required)
- version (str): 'v2' for reCAPTCHA v2, 'v3' for reCAPTCHA v3 (default: 'v2')
- enterprise (int): 1 for reCAPTCHA Enterprise, 0 for regular (default: 0)
- domain (str): 'google.com' or 'recaptcha.net' (default: 'google.com')
- invisible (int): 1 for invisible reCAPTCHA, 0 for visible (default: 0)
- action (str): Action parameter for v3 (default: 'verify')
- score (float): Minimum score for v3 (default: 0.4, max achievable ~0.3)
- data-s (str): Value of data-s parameter for Google Search/services
- cookies (str): Cookies in format 'KEY1:Value1;KEY2:Value2'
- userAgent (str): User agent string for browser simulation
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains the response token
"""Solves FunCaptcha (ArkoseLabs) interactive puzzles and challenges.
def funcaptcha(self, sitekey, url, **kwargs):
"""
Solve FunCaptcha/ArkoseLabs challenges.
Parameters:
- sitekey (str): Value of pk or data-pkey parameter (required)
- url (str): Full URL where FunCaptcha is located (required)
- surl (str): Value of surl parameter if present
- userAgent (str): User agent string for browser simulation
- data (dict): Custom data parameters in format {'key': 'value'}
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains the response token
"""Solves GeeTest sliding puzzle and behavioral captchas.
def geetest(self, gt, challenge, url, **kwargs):
"""
Solve GeeTest captcha challenges.
Parameters:
- gt (str): Value of gt parameter from the page (required)
- challenge (str): Value of challenge parameter from the page (required)
- url (str): Full URL where GeeTest is located (required)
- offline (int): 1 if initGeetest called with offline=true (default: 0)
- new_captcha (int): 1 if initGeetest called with new_captcha=true (default: 0)
- userAgent (str): User agent string for browser simulation
- apiServer (str): Value of api_server parameter if present
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains challenge solution
"""Solves the newer GeeTest v4 captcha system with enhanced behavioral analysis.
def geetest_v4(self, captchaId, url, **kwargs):
"""
Solve GeeTest v4 captcha.
Parameters:
- captchaId (str): GeeTest v4 captcha ID from the page (required)
- url (str): Full URL where GeeTest v4 is located (required)
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains v4 solution
"""Solves hCaptcha challenges including invisible variants.
def hcaptcha(self, sitekey, url, **kwargs):
"""
Solve hCaptcha challenges.
Parameters:
- sitekey (str): Value of data-sitekey parameter (required)
- url (str): Full URL where hCaptcha is located (required)
- invisible (int): 1 for invisible hCaptcha (rare), 0 for visible (default: 0)
- data (str): Custom rqdata value for some implementations
- domain (str): 'hcaptcha.com' or 'js.hcaptcha.com' (default: 'hcaptcha.com')
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains the response token
"""from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Standard reCAPTCHA v2
result = solver.recaptcha(
sitekey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-',
url='https://www.google.com/recaptcha/api2/demo'
)
print(f"reCAPTCHA token: {result['code']}")
# Invisible reCAPTCHA with proxy
result = solver.recaptcha(
sitekey='your_site_key',
url='https://example.com/form',
invisible=1,
proxy={'type': 'HTTPS', 'uri': 'user:pass@proxy.com:8080'}
)
print(f"Token: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# reCAPTCHA v3 with specific action and score
result = solver.recaptcha(
sitekey='your_v3_site_key',
url='https://example.com/form',
version='v3',
action='homepage',
score=0.3
)
print(f"v3 token: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# reCAPTCHA Enterprise with custom user agent
result = solver.recaptcha(
sitekey='enterprise_site_key',
url='https://enterprise-site.com',
enterprise=1,
userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
)
print(f"Enterprise token: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Basic FunCaptcha
result = solver.funcaptcha(
sitekey='your_public_key',
url='https://example.com/login'
)
print(f"FunCaptcha token: {result['code']}")
# FunCaptcha with custom data
result = solver.funcaptcha(
sitekey='your_public_key',
url='https://example.com/register',
surl='https://api.funcaptcha.com',
data={'blob': 'custom_data_here'}
)
print(f"Token: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Standard GeeTest
result = solver.geetest(
gt='gt_value_from_page',
challenge='challenge_value_from_page',
url='https://example.com/login'
)
print(f"GeeTest solution: {result['code']}")
# GeeTest with offline mode
result = solver.geetest(
gt='gt_value',
challenge='challenge_value',
url='https://example.com',
offline=1,
new_captcha=1
)
print(f"Offline solution: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# GeeTest v4
result = solver.geetest_v4(
captchaId='geetest_v4_captchaId',
url='https://example.com/v4-captcha'
)
print(f"GeeTest v4 solution: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Standard hCaptcha
result = solver.hcaptcha(
sitekey='hcaptcha_site_key',
url='https://example.com/form'
)
print(f"hCaptcha token: {result['code']}")
# Invisible hCaptcha with custom data
result = solver.hcaptcha(
sitekey='invisible_site_key',
url='https://example.com',
invisible=1,
data='custom_rqdata_value'
)
print(f"Invisible token: {result['code']}")from twocaptcha import TwoCaptcha, ApiException, TimeoutException
solver = TwoCaptcha('your_api_key', recaptchaTimeout=900) # 15 minutes
try:
result = solver.recaptcha(
sitekey='invalid_sitekey',
url='https://example.com'
)
except ApiException as e:
print(f"API error: {e}")
except TimeoutException as e:
print(f"Timeout error: {e}")
except Exception as e:
print(f"Other error: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-2captcha-python