Anti-Captcha Official Python Library

1.0.69 · active · verified Fri Apr 17

The `anticaptchaofficial` library is the official Python client for anti-captcha.com, providing an easy way to integrate various captcha solving services into your applications. It supports Image Captcha, reCAPTCHA v2/v3, hCaptcha, FunCaptcha, Geetest, and Square Net. The current version is 1.0.69, and it maintains an active release cadence with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to solve a reCAPTCHA v2 challenge using the `RecaptchaV2Solver`. It highlights setting the API key, configuring verbose output, and providing the necessary `page_url` and `site_key`. The `solve_and_return_solution` method initiates the solving process and returns the captcha token or `0` on failure, with error details available in `solver.error_text`.

import os
from anticaptchaofficial.recaptchav2 import RecaptchaV2Solver

# It's recommended to store your API key in an environment variable.
api_key = os.environ.get('ANTI_CAPTCHA_API_KEY', 'YOUR_API_KEY_HERE')

if api_key == 'YOUR_API_KEY_HERE':
    print("WARNING: Please set the ANTI_CAPTCHA_API_KEY environment variable or replace 'YOUR_API_KEY_HERE' with your actual key.")
    # In a production application, you would typically exit or raise an error here.
    exit(1)

solver = RecaptchaV2Solver()
solver.set_key(api_key)
solver.set_verbose(1) # Optional: set to 1 for more verbose output during solving

# --- Required parameters for reCAPTCHA V2 ---
# The URL of the page where the captcha is located
page_url = "https://www.google.com/recaptcha/api2/demo" 
# The site key (data-sitekey) found in the HTML of the target page
site_key = "6Le-wvkSAAAAAPBMRTvw0Q4McdvzF00uzpXu7B0r" 

print(f"Attempting to solve reCAPTCHA V2 for {page_url} with site key {site_key}...")

# Solve the captcha
captcha_response = solver.solve_and_return_solution(page_url, site_key)

if captcha_response != 0:
    print(f"Captcha successfully solved! Response token: {captcha_response}")
    print("You can now submit this token to the target website's form.")
else:
    print(f"Failed to solve captcha. Error: {solver.error_text}")
    print(f"Error code: {solver.error_code}")

view raw JSON →