Skip to content
CaptchaSonic Docs

Recaptcha V2

This is a helper code, you can just copy and paste and run.

import requests


def fetch_recaptchaV2_result():
    url = "https://api.example.com/ocr"  # Replace with the actual API endpoint
    headers = {"Content-Type": "application/json"}

    data = {
        "apiKey": "sonic_xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "task": {
          "type": "ReCaptchaV2Image",
          "questionType": "33",
          "queries": [
          "iVBORw0KGgoAAAANSUhEUgAAASwAAADICAIAAADdvUsCAAAgAElEQVR4AezBCZRd9X0n...."
          ],
          "question": "cars",
          "websiteURL": "https://your-website.com",
          "metadata": {
          "pageURL": "www.website.com",
          "title": "reCAPTCHA"
          }
        }
    }

    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()  # Raise an error for HTTP error responses 
        (4xx, 5xx)
        return response.json()  # Return JSON response
    except requests.exceptions.RequestException as e:
        print(f"Error fetching OCR result: {e}")
        return None

  # Example usage:
  result = fetch_recaptchaV2_result()
  if result:
      print("Response:", result)