From bdacf7ff25fde2fc3abce8500c478acd9d18e82a Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 16:52:36 +0300 Subject: [PATCH 01/18] feat: add debug mode --- README.md | 30 ++++ captcha_solver_api/_debug.py | 219 +++++++++++++++++++++++++++++ captcha_solver_api/async_client.py | 158 ++++++++++++++++----- captcha_solver_api/client.py | 158 ++++++++++++++++----- examples/sync/debug_mode.py | 38 +++++ tests/async/test_async_debug.py | 85 +++++++++++ tests/sync/test_debug.py | 182 ++++++++++++++++++++++++ 7 files changed, 802 insertions(+), 68 deletions(-) create mode 100644 captcha_solver_api/_debug.py create mode 100644 examples/sync/debug_mode.py create mode 100644 tests/async/test_async_debug.py create mode 100644 tests/sync/test_debug.py diff --git a/README.md b/README.md index d9933d5..c7d12d1 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Full API reference (all endpoints, error codes, captcha-type details): **https:/ - [Tencent](#tencent) - [Advanced Usage](#advanced-usage) - [Check balance](#check-balance) + - [Debug mode](#debug-mode) - [Custom timeout and polling](#custom-timeout-and-polling) - [Worker language pool](#worker-language-pool) - [Async client](#async-client) @@ -189,6 +190,7 @@ Constructor. | `timeout` | `int` | `120` | Polling window after task creation, in seconds. Overridable per call; each HTTP request has a separate 30-second timeout. | | `polling_interval` | `int` | `10` | Seconds before the first `getTaskResult` poll and between subsequent polls. | | `language_pool` | `Optional[str]` | `None` | Default worker pool (`"en"` or `"ru"`) applied to every call that doesn't pass its own `language_pool`. | +| `debug` | `bool` | `False` | Emit sanitized request/response, timing, polling, error, and solve summary logs. | Both clients hold a reusable connection pool (`requests.Session` / `httpx.AsyncClient`) for their lifetime instead of opening one per request. Close it when you're done -- @@ -684,6 +686,34 @@ balance = client.get_balance() print(f"Balance: {balance}") ``` +### Debug mode + +Pass `debug=True` to either client to diagnose an integration. The SDK logs its version and +configuration, each HTTP operation and duration, compact one-line `processing` polls, detailed +sanitized request/response blocks for completed operations and failures, and a `SOLVE SUMMARY` +after every `solve()` call (including failed calls). Debug mode is never enabled from an +environment variable and logging failures do not change request results or SDK exceptions. + +```python +client = CaptchaClient("your_api_key", debug=True) +solution = client.solve(task) +``` + +Credential, cookie, and proxy fields are replaced with `[MASKED]`. Base64 image fields are +replaced with their character count, and other strings longer than 200 characters retain only +their first and last 40 characters plus the original length. The SDK does not log HTTP headers. +URLs and custom task fields can still contain application data, so review logs before sharing +them publicly. + +Run the dedicated example from the repository root: + +```bash +python examples/sync/debug_mode.py +``` + +It reads `CAPTCHA_API_KEY` from the environment or `.env`, uses the bundled image asset, and +creates a real paid CAPTCHA task. See [`examples/sync/debug_mode.py`](examples/sync/debug_mode.py). + ### Custom timeout and polling ```python diff --git a/captcha_solver_api/_debug.py b/captcha_solver_api/_debug.py new file mode 100644 index 0000000..c53e804 --- /dev/null +++ b/captcha_solver_api/_debug.py @@ -0,0 +1,219 @@ +"""Internal, best-effort debug logging helpers.""" + +from __future__ import annotations + +import json +import logging +from datetime import datetime +from typing import Any, Dict, List, Optional + +_MASKED_KEYS = { + "authorization", + "clientkey", + "cookie", + "cookies", + "password", + "proxyaddress", + "proxylogin", + "proxypassword", +} +_BASE64_KEYS = {"body", "image", "imginstructions"} +_handler: Optional[logging.Handler] = None + + +def _sanitize(value: Any, key: str = "") -> Any: + """Return a sanitized copy suitable for diagnostic output.""" + normalized_key = key.lower() + if normalized_key in _MASKED_KEYS: + return "[MASKED]" + if normalized_key in _BASE64_KEYS and isinstance(value, str): + return f"[base64, {len(value)} chars]" + if isinstance(value, dict): + return {item_key: _sanitize(item, str(item_key)) for item_key, item in value.items()} + if isinstance(value, (list, tuple)): + return [_sanitize(item) for item in value] + if isinstance(value, str) and len(value) > 200: + return f"{value[:40]}...{value[-40:]} [truncated, {len(value)} chars]" + return value + + +def _json(value: Any) -> str: + return json.dumps(_sanitize(value), indent=2, ensure_ascii=False, default=repr) + + +def _timestamp() -> str: + now = datetime.now().astimezone() + offset = now.strftime("%z") + offset = f"{offset[:3]}:{offset[3:]}" + return now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] + f" {offset}" + + +def _error_details(error: BaseException) -> str: + details: List[str] = [] + current: Optional[BaseException] = error + seen = set() + while current is not None and len(details) < 4 and id(current) not in seen: + seen.add(id(current)) + text = str(current).replace("\n", " ").strip() + details.append(f"{type(current).__name__}: {text}" if text else type(current).__name__) + current = current.__cause__ or current.__context__ + return " <- ".join(details) + + +class DebugLogger: + """Emit complete logical events while never affecting SDK behavior.""" + + def __init__(self, enabled: bool, name: str) -> None: + self.enabled = enabled + self.name = name + self.logger = logging.getLogger(f"captcha_solver_api.{name}") + if enabled: + self._ensure_default_handler() + + def _ensure_default_handler(self) -> None: + global _handler + if _handler is None: + _handler = logging.StreamHandler() + _handler.setFormatter(logging.Formatter("%(message)s")) + if _handler not in self.logger.handlers: + self.logger.addHandler(_handler) + self.logger.setLevel(logging.DEBUG) + self.logger.propagate = False + + def emit(self, message: str) -> None: + if not self.enabled: + return + try: + self.logger.debug(f"[{_timestamp()}] [{self.name}] {message}") + except Exception: + pass + + def initialized(self, version: str, base_url: str, timeout: Any, polling: Any) -> None: + self.emit( + "initialized\n" + f" sdkVersion: {version}\n" + f" baseUrl: {base_url}\n" + " httpTimeout: 30s\n" + f" pollingTimeout: {timeout}s\n" + f" pollingInterval: {polling}s" + ) + + def request_success( + self, + endpoint: str, + url: str, + payload: Dict[str, Any], + data: Dict[str, Any], + status: int, + reason: str, + elapsed_ms: int, + ) -> None: + try: + summary = _summary(endpoint, payload, data) + if endpoint == "getTaskResult" and data.get("status") == "processing": + self.emit(f"{summary} ({elapsed_ms}ms)") + return + self.emit( + f"{summary} ({elapsed_ms}ms)\n" + f"REQUEST (POST {url}):\n{_json(payload)}\n" + f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms):\n{_json(data)}" + ) + except Exception: + pass + + def request_failure( + self, + endpoint: str, + url: str, + payload: Dict[str, Any], + error: BaseException, + elapsed_ms: int, + status: Optional[int] = None, + reason: str = "", + data: Optional[Any] = None, + invalid_json: bool = False, + body_missing: bool = False, + ) -> None: + try: + context = _request_context(endpoint, payload) + detail = _error_details(error) + if status is None: + response = ( + "RESPONSE: none - no response from the server " + f"({type(error).__name__}, {elapsed_ms}ms)" + ) + elif body_missing: + response = ( + f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms): " + f"body was not received ({type(error).__name__})" + ) + elif invalid_json: + response = ( + f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms): " + "body is not valid JSON" + ) + else: + response = f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms):\n{_json(data)}" + self.emit( + f"{endpoint} {context} -> failed: {detail} ({elapsed_ms}ms)\n" + f"REQUEST (POST {url}):\n{_json(payload)}\n{response}" + ) + except Exception: + pass + + def solve_summary( + self, + solved: bool, + task_id: Optional[int], + task_type: Optional[str], + elapsed: float, + polls: int, + result: Optional[Dict[str, Any]] = None, + error: Optional[BaseException] = None, + ) -> None: + try: + server_time = "-" + if result is not None: + created = result.get("createTime") + ended = result.get("endTime") + if isinstance(created, (int, float)) and isinstance(ended, (int, float)): + server_time = f"{ended - created:g}s" + lines = [ + "SOLVE SUMMARY:", + f" status: {'solved' if solved else 'not solved'}", + f" taskId: {task_id if task_id is not None else '- (task was not created)'}", + f" taskType: {task_type or '-'}", + f" elapsed: {elapsed:.3f}s", + f" serverSolveTime: {server_time}", + f" polls: {polls}", + ] + if error is not None: + lines.append(f" error: {_error_details(error)}") + self.emit("\n".join(lines)) + except Exception: + pass + + +def _request_context(endpoint: str, payload: Dict[str, Any]) -> str: + if endpoint == "createTask": + task = payload.get("task") + return str(task.get("type", "unknown")) if isinstance(task, dict) else "unknown" + if endpoint == "getTaskResult": + return f"taskId={payload.get('taskId', 'unknown')}" + return "" + + +def _summary(endpoint: str, payload: Dict[str, Any], data: Dict[str, Any]) -> str: + context = _request_context(endpoint, payload) + prefix = f"{endpoint} {context}".rstrip() + if data.get("errorId", 0) != 0: + code = data.get("errorCode", "UNKNOWN_ERROR") + message = data.get("errorDescription", "Unknown API error.") + return f"{prefix} -> failed: ApiError [{code}] {message}" + if endpoint == "createTask": + return f"{prefix} -> taskId={data.get('taskId')}" + if endpoint == "getTaskResult": + return f"{prefix} -> {data.get('status', 'unknown')}" + if endpoint == "getBalance": + return f"{prefix} -> balance={data.get('balance')}" + return f"{prefix} -> success" diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index 921d1ea..e8c6509 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -12,6 +12,7 @@ import httpx +from ._debug import DebugLogger from ._version import __version__ from .exceptions import ( ApiError, @@ -42,6 +43,8 @@ class AsyncCaptchaClient: Defaults to 10. Waiting does not block the event loop. language_pool: Default worker pool, e.g. `"en"` or `"ru"`. `None` uses the account default. Can be overridden in `solve()` or `create_task()`. + debug: Emit sanitized request, response, timing, and solve summary logs. + Defaults to `False`. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -70,6 +73,7 @@ def __init__( timeout: int = 120, polling_interval: int = 10, language_pool: Optional[str] = None, + debug: bool = False, ) -> None: """Create an async client with a reusable HTTP connection pool. @@ -88,6 +92,7 @@ def __init__( applied to every `create_task()`/`solve()` call that doesn't pass its own `language_pool`. Leave unset to use the account's default pool. + debug: Enable sanitized diagnostic logging. Defaults to `False`. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -100,6 +105,8 @@ def __init__( self.timeout = timeout self.polling_interval = polling_interval self.language_pool = language_pool + self.debug = debug + self._debug = DebugLogger(debug, "AsyncCaptchaClient") self._client = httpx.AsyncClient( follow_redirects=True, @@ -109,6 +116,7 @@ def __init__( "X-SDK": f"python-sdk/{__version__}", }, ) + self._debug.initialized(__version__, self.base_url, self.timeout, self.polling_interval) async def aclose(self) -> None: """Closes the underlying connection pool. Call this when you're done with @@ -128,22 +136,83 @@ async def _request( payload: Dict[str, Any], ) -> Dict[str, Any]: url = f"{self.base_url}/{endpoint.lstrip('/')}" + started = time.monotonic() try: response = await self._client.post(url, json=payload, timeout=30) response.raise_for_status() except httpx.TimeoutException as exc: + response = getattr(exc, "response", None) + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=getattr(response, "status_code", None), + reason=getattr(response, "reason_phrase", "") or "", + body_missing=response is not None, + ) raise CaptchaTimeoutError("Request timed out.") from exc except httpx.HTTPError as exc: + response = getattr(exc, "response", None) + data = None + invalid_json = False + if response is not None: + try: + data = response.json() + except ValueError: + invalid_json = True + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=getattr(response, "status_code", None), + reason=getattr(response, "reason_phrase", "") or "", + data=data, + invalid_json=invalid_json, + ) raise NetworkError(str(exc)) from exc try: data = response.json() except ValueError as exc: + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=response.status_code, + reason=response.reason_phrase or "", + invalid_json=True, + ) raise NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") from exc if not isinstance(data, dict): - raise NetworkError(f"Unexpected API response shape: {type(data).__name__}") + error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") + self._debug.request_failure( + endpoint, + url, + payload, + error, + round((time.monotonic() - started) * 1000), + status=response.status_code, + reason=response.reason_phrase or "", + data=data, + ) + raise error + self._debug.request_success( + endpoint, + url, + payload, + data, + response.status_code, + response.reason_phrase or "", + round((time.monotonic() - started) * 1000), + ) return data def _ensure_success(self, data: Dict[str, Any]) -> None: @@ -309,38 +378,59 @@ async def solve( token = solution["gRecaptchaResponse"] """ - task_id = await self.create_task(task, language_pool=language_pool) - - deadline = time.monotonic() + (timeout if timeout is not None else self.timeout) - poll_failures = 0 - - while time.monotonic() < deadline: - remaining = deadline - time.monotonic() - await asyncio.sleep(min(self.polling_interval, max(0, remaining))) - if time.monotonic() >= deadline: - break - try: - result = await self.get_task_result(task_id) - except (NetworkError, CaptchaTimeoutError): - # getTaskResult is safe to repeat: retry a short transport - # failure on the next poll instead of losing a paid task. - poll_failures += 1 - if poll_failures > self.poll_retries: - raise - continue + started = time.monotonic() + task_id: Optional[int] = None + task_type = getattr(task, "type", None) + polls = 0 + final_result: Optional[Dict[str, Any]] = None + solved = False + error: Optional[BaseException] = None + try: + task_id = await self.create_task(task, language_pool=language_pool) + deadline = time.monotonic() + (timeout if timeout is not None else self.timeout) poll_failures = 0 - if result.get("status") == "ready": - solution = result["solution"] - if not isinstance(solution, (dict, str)) or solution == "": - raise NetworkError( - "API returned a ready task without a valid solution", - task_id=task_id, - ) - return solution - - raise CaptchaTimeoutError( - f"Task {task_id} was not solved within the polling timeout. It may still " - f"be solved later: check it with get_task_result({task_id}).", - task_id=task_id, - ) + while time.monotonic() < deadline: + remaining = deadline - time.monotonic() + await asyncio.sleep(min(self.polling_interval, max(0, remaining))) + if time.monotonic() >= deadline: + break + try: + polls += 1 + result = await self.get_task_result(task_id) + except (NetworkError, CaptchaTimeoutError): + poll_failures += 1 + if poll_failures > self.poll_retries: + raise + continue + poll_failures = 0 + + if result.get("status") == "ready": + final_result = result + solution = result["solution"] + if not isinstance(solution, (dict, str)) or solution == "": + raise NetworkError( + "API returned a ready task without a valid solution", + task_id=task_id, + ) + solved = True + return solution + + raise CaptchaTimeoutError( + f"Task {task_id} was not solved within the polling timeout. It may still " + f"be solved later: check it with get_task_result({task_id}).", + task_id=task_id, + ) + except BaseException as exc: + error = exc + raise + finally: + self._debug.solve_summary( + solved, + task_id, + task_type, + time.monotonic() - started, + polls, + final_result, + error, + ) diff --git a/captcha_solver_api/client.py b/captcha_solver_api/client.py index 3b48ed2..82518c2 100644 --- a/captcha_solver_api/client.py +++ b/captcha_solver_api/client.py @@ -9,6 +9,7 @@ import requests +from ._debug import DebugLogger from ._version import __version__ from .exceptions import ( ApiError, @@ -32,6 +33,8 @@ class CaptchaClient: Defaults to 10. language_pool: Default worker pool, e.g. `"en"` or `"ru"`. `None` uses the account default. Can be overridden in `solve()` or `create_task()`. + debug: Emit sanitized request, response, timing, and solve summary logs. + Defaults to `False`. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -60,6 +63,7 @@ def __init__( timeout: int = 120, polling_interval: int = 10, language_pool: Optional[str] = None, + debug: bool = False, ) -> None: """Create a client with a reusable HTTP connection pool. @@ -78,6 +82,7 @@ def __init__( applied to every `create_task()`/`solve()` call that doesn't pass its own `language_pool`. Leave unset to use the account's default pool. + debug: Enable sanitized diagnostic logging. Defaults to `False`. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -90,6 +95,8 @@ def __init__( self.timeout = timeout self.polling_interval = polling_interval self.language_pool = language_pool + self.debug = debug + self._debug = DebugLogger(debug, "CaptchaClient") self.session = requests.Session() self.session.headers.update( @@ -99,6 +106,7 @@ def __init__( "X-SDK": f"python-sdk/{__version__}", } ) + self._debug.initialized(__version__, self.base_url, self.timeout, self.polling_interval) def close(self) -> None: """Closes the underlying connection pool. Call this when you're done with @@ -118,22 +126,83 @@ def _request( payload: Dict[str, Any], ) -> Dict[str, Any]: url = f"{self.base_url}/{endpoint.lstrip('/')}" + started = time.monotonic() try: response = self.session.post(url, json=payload, timeout=30) response.raise_for_status() except requests.exceptions.Timeout as exc: + response = getattr(exc, "response", None) + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=getattr(response, "status_code", None), + reason=getattr(response, "reason", "") or "", + body_missing=response is not None, + ) raise CaptchaTimeoutError("Request timed out.") from exc except requests.exceptions.RequestException as exc: + response = getattr(exc, "response", None) + data = None + invalid_json = False + if response is not None: + try: + data = response.json() + except ValueError: + invalid_json = True + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=getattr(response, "status_code", None), + reason=getattr(response, "reason", "") or "", + data=data, + invalid_json=invalid_json, + ) raise NetworkError(str(exc)) from exc try: data = response.json() except ValueError as exc: + self._debug.request_failure( + endpoint, + url, + payload, + exc, + round((time.monotonic() - started) * 1000), + status=response.status_code, + reason=response.reason or "", + invalid_json=True, + ) raise NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") from exc if not isinstance(data, dict): - raise NetworkError(f"Unexpected API response shape: {type(data).__name__}") + error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") + self._debug.request_failure( + endpoint, + url, + payload, + error, + round((time.monotonic() - started) * 1000), + status=response.status_code, + reason=response.reason or "", + data=data, + ) + raise error + self._debug.request_success( + endpoint, + url, + payload, + data, + response.status_code, + response.reason or "", + round((time.monotonic() - started) * 1000), + ) return data def _ensure_success(self, data: Dict[str, Any]) -> None: @@ -287,38 +356,59 @@ def solve( token = solution["gRecaptchaResponse"] """ - task_id = self.create_task(task, language_pool=language_pool) - - deadline = time.monotonic() + (timeout if timeout is not None else self.timeout) - poll_failures = 0 - - while time.monotonic() < deadline: - remaining = deadline - time.monotonic() - time.sleep(min(self.polling_interval, max(0, remaining))) - if time.monotonic() >= deadline: - break - try: - result = self.get_task_result(task_id) - except (NetworkError, CaptchaTimeoutError): - # getTaskResult is safe to repeat: retry a short transport - # failure on the next poll instead of losing a paid task. - poll_failures += 1 - if poll_failures > self.poll_retries: - raise - continue + started = time.monotonic() + task_id: Optional[int] = None + task_type = getattr(task, "type", None) + polls = 0 + final_result: Optional[Dict[str, Any]] = None + solved = False + error: Optional[BaseException] = None + try: + task_id = self.create_task(task, language_pool=language_pool) + deadline = time.monotonic() + (timeout if timeout is not None else self.timeout) poll_failures = 0 - if result.get("status") == "ready": - solution = result["solution"] - if not isinstance(solution, (dict, str)) or solution == "": - raise NetworkError( - "API returned a ready task without a valid solution", - task_id=task_id, - ) - return solution - - raise CaptchaTimeoutError( - f"Task {task_id} was not solved within the polling timeout. It may still " - f"be solved later: check it with get_task_result({task_id}).", - task_id=task_id, - ) + while time.monotonic() < deadline: + remaining = deadline - time.monotonic() + time.sleep(min(self.polling_interval, max(0, remaining))) + if time.monotonic() >= deadline: + break + try: + polls += 1 + result = self.get_task_result(task_id) + except (NetworkError, CaptchaTimeoutError): + poll_failures += 1 + if poll_failures > self.poll_retries: + raise + continue + poll_failures = 0 + + if result.get("status") == "ready": + final_result = result + solution = result["solution"] + if not isinstance(solution, (dict, str)) or solution == "": + raise NetworkError( + "API returned a ready task without a valid solution", + task_id=task_id, + ) + solved = True + return solution + + raise CaptchaTimeoutError( + f"Task {task_id} was not solved within the polling timeout. It may still " + f"be solved later: check it with get_task_result({task_id}).", + task_id=task_id, + ) + except BaseException as exc: + error = exc + raise + finally: + self._debug.solve_summary( + solved, + task_id, + task_type, + time.monotonic() - started, + polls, + final_result, + error, + ) diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py new file mode 100644 index 0000000..5c1f048 --- /dev/null +++ b/examples/sync/debug_mode.py @@ -0,0 +1,38 @@ +"""Run one Image to Text task with sanitized debug logging enabled. + +This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment +or in the repository's .env file before running it. +""" + +import os +import sys +from base64 import b64encode + +try: + from dotenv import load_dotenv +except ModuleNotFoundError as exc: + if exc.name != "dotenv": + raise + load_dotenv = None + +repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +sys.path.append(repo_root) +if load_dotenv is not None: + load_dotenv(os.path.join(repo_root, ".env")) + +from captcha_solver_api import CaptchaClient +from captcha_solver_api.tasks import ImageToTextTask + +api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") +image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") + +with open(image_path, "rb") as image_file: + image_body = b64encode(image_file.read()).decode("utf-8") + +with CaptchaClient(api_key, debug=True) as client: + solution = client.solve( + ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6) + ) + +# The SOLVE SUMMARY is emitted before solve() returns, so this is printed last. +print(f"Recognized text: {solution['text']}") diff --git a/tests/async/test_async_debug.py b/tests/async/test_async_debug.py new file mode 100644 index 0000000..3bcb7fd --- /dev/null +++ b/tests/async/test_async_debug.py @@ -0,0 +1,85 @@ +from unittest.mock import AsyncMock, Mock, patch + +import httpx +import pytest + +from captcha_solver_api import AsyncCaptchaClient, CaptchaTimeoutError, NetworkError +from captcha_solver_api.tasks import ImageToTextTask + + +def messages(client): + return [call.args[0] for call in client._debug.logger.debug.call_args_list] + + +async def test_async_debug_success_processing_summary_and_masking(): + client = AsyncCaptchaClient("async-secret", polling_interval=0, debug=True) + client._debug.logger.debug = Mock() + task = ImageToTextTask(body="A" * 300) + responses = [ + httpx.Response(200, json={"errorId": 0, "taskId": 9}, request=httpx.Request("POST", "https://x")), + httpx.Response( + 200, + json={"errorId": 0, "status": "processing"}, + request=httpx.Request("POST", "https://x"), + ), + httpx.Response( + 200, + json={ + "errorId": 0, + "status": "ready", + "createTime": 2, + "endTime": 5, + "solution": {"text": "1234"}, + }, + request=httpx.Request("POST", "https://x"), + ), + ] + client._client.post = AsyncMock(side_effect=responses) + + assert await client.solve(task) == {"text": "1234"} + + output = "\n".join(messages(client)) + assert "async-secret" not in output + assert "[base64, 300 chars]" in output + assert "getTaskResult taskId=9 -> processing" in output + assert "SOLVE SUMMARY" in output + assert "polls: 2" in output + assert "serverSolveTime: 3s" in output + await client.aclose() + + +async def test_async_debug_transport_timeout_and_isolation(): + client = AsyncCaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + client._client.post = AsyncMock(side_effect=httpx.ConnectError("dns failed")) + with pytest.raises(NetworkError): + await client.get_balance() + assert "RESPONSE: none - no response from the server" in messages(client)[0] + + client._debug.logger.debug = Mock() + client._client.post = AsyncMock(side_effect=httpx.ReadTimeout("slow")) + with pytest.raises(CaptchaTimeoutError): + await client.get_balance() + assert "Timeout" in messages(client)[0] + + client._debug.logger.debug = Mock(side_effect=RuntimeError("logger failed")) + client._client.post = AsyncMock( + return_value=httpx.Response( + 200, json={"errorId": 0, "balance": 1.25}, request=httpx.Request("POST", "https://x") + ) + ) + assert await client.get_balance() == 1.25 + await client.aclose() + + +async def test_async_failed_solve_has_summary_when_task_not_created(): + client = AsyncCaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + task = ImageToTextTask(body="image") + with patch.object(client, "create_task", side_effect=NetworkError("offline")): + with pytest.raises(NetworkError): + await client.solve(task) + summary = messages(client)[0] + assert "status: not solved" in summary + assert "taskId: - (task was not created)" in summary + await client.aclose() diff --git a/tests/sync/test_debug.py b/tests/sync/test_debug.py new file mode 100644 index 0000000..fb53ed1 --- /dev/null +++ b/tests/sync/test_debug.py @@ -0,0 +1,182 @@ +from unittest.mock import Mock, patch + +import pytest +import requests + +from captcha_solver_api import ApiError, CaptchaClient, CaptchaTimeoutError, NetworkError +from captcha_solver_api.tasks import ImageToTextTask + + +def response(status=200, reason="OK", data=None): + result = Mock(status_code=status, reason=reason, text="response text") + result.json.return_value = data + if status >= 400: + error = requests.HTTPError(f"{status} {reason}", response=result) + result.raise_for_status.side_effect = error + return result + + +def debug_messages(client): + return [call.args[0] for call in client._debug.logger.debug.call_args_list] + + +def test_debug_is_disabled_by_default(): + client = CaptchaClient("secret") + assert client.debug is False + assert client._debug.enabled is False + + +def test_debug_initialization_is_one_timestamped_event(): + with patch("logging.Logger.debug") as logger: + CaptchaClient("secret", debug=True) + + logger.assert_called_once() + message = logger.call_args.args[0] + assert message.startswith("[") + assert "] [CaptchaClient] initialized" in message + assert "sdkVersion:" in message + assert "baseUrl:" in message + assert "pollingInterval:" in message + + +def test_success_masks_and_truncates_without_mutating_payload(): + client = CaptchaClient("api-secret", debug=True) + client._debug.logger.debug = Mock() + long_token = "x" * 250 + body = "Y" * 300 + payload = { + "clientKey": "api-secret", + "cookie": "session=secret", + "proxyAddress": "127.0.0.1", + "task": {"type": "ImageToTextTask", "body": body}, + } + client.session.post = Mock( + return_value=response( + data={"errorId": 0, "taskId": 123, "solution": {"token": long_token}} + ) + ) + + result = client._request("createTask", payload) + + assert result["taskId"] == 123 + message = debug_messages(client)[0] + assert "REQUEST (POST" in message and "RESPONSE (HTTP 200 OK" in message + assert "api-secret" not in message + assert "session=secret" not in message + assert "127.0.0.1" not in message + assert "[MASKED]" in message + assert "[base64, 300 chars]" in message + assert "[truncated, 250 chars]" in message + assert payload["clientKey"] == "api-secret" + assert payload["task"]["body"] == body + + +def test_processing_is_compact_single_line(): + client = CaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + client.session.post = Mock(return_value=response(data={"errorId": 0, "status": "processing"})) + + client.get_task_result(42) + + message = debug_messages(client)[0] + assert "getTaskResult taskId=42 -> processing" in message + assert "REQUEST" not in message + assert "\n" not in message + + +def test_api_and_http_errors_include_paired_request_response(): + client = CaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + client.session.post = Mock( + side_effect=[ + response( + data={ + "errorId": 1, + "errorCode": "ERROR_KEY_DOES_NOT_EXIST", + "errorDescription": "Account not found", + } + ), + response(502, "Bad Gateway", {"message": "upstream failed"}), + ] + ) + + with pytest.raises(ApiError): + client.get_balance() + with pytest.raises(NetworkError): + client.get_balance() + + api_message, http_message = debug_messages(client) + assert "failed: ApiError [ERROR_KEY_DOES_NOT_EXIST]" in api_message + assert "REQUEST" in api_message and "RESPONSE (HTTP 200 OK" in api_message + assert "failed: HTTPError" in http_message + assert "RESPONSE (HTTP 502 Bad Gateway" in http_message + assert "upstream failed" in http_message + + +def test_invalid_json_network_and_timeout_explain_missing_response(): + client = CaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + invalid = response() + invalid.json.side_effect = ValueError("bad json") + client.session.post = Mock( + side_effect=[invalid, requests.ConnectionError("dns failed"), requests.Timeout("slow")] + ) + + with pytest.raises(NetworkError): + client.get_balance() + with pytest.raises(NetworkError): + client.get_balance() + with pytest.raises(CaptchaTimeoutError): + client.get_balance() + + invalid_message, network_message, timeout_message = debug_messages(client) + assert "body is not valid JSON" in invalid_message + assert "RESPONSE: none - no response from the server (ConnectionError" in network_message + assert "RESPONSE: none - no response from the server (Timeout" in timeout_message + + +def test_solve_summary_reports_success_failure_and_poll_count(): + task = ImageToTextTask(body="image") + client = CaptchaClient("secret", polling_interval=0, debug=True) + client._debug.logger.debug = Mock() + with patch.object(client, "_request") as request: + request.side_effect = [ + {"errorId": 0, "taskId": 7}, + {"errorId": 0, "status": "processing"}, + { + "errorId": 0, + "status": "ready", + "createTime": 10, + "endTime": 18, + "solution": {"text": "1234"}, + }, + ] + assert client.solve(task) == {"text": "1234"} + + summary = debug_messages(client)[0] + assert "SOLVE SUMMARY" in summary + assert "status: solved" in summary + assert "taskId: 7" in summary + assert "taskType: ImageToTextTask" in summary + assert "serverSolveTime: 8s" in summary + assert "polls: 2" in summary + + client._debug.logger.debug.reset_mock() + with patch.object(client, "create_task", side_effect=ApiError("BAD", "failed")): + with pytest.raises(ApiError): + client.solve(task) + summary = debug_messages(client)[0] + assert "status: not solved" in summary + assert "taskId: - (task was not created)" in summary + assert "error:" in summary + + +def test_debug_failure_does_not_change_result_or_exception(): + client = CaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock(side_effect=RuntimeError("logger failed")) + client.session.post = Mock(return_value=response(data={"errorId": 0, "balance": 4.5})) + assert client.get_balance() == 4.5 + + client.session.post = Mock(side_effect=requests.ConnectionError("original failure")) + with pytest.raises(NetworkError, match="original failure"): + client.get_balance() From 3e15519938269d166d20bd3471d82a22284c87e2 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 16:57:27 +0300 Subject: [PATCH 02/18] fix: satisfy lint and security checks --- captcha_solver_api/_debug.py | 11 +++++------ examples/sync/debug_mode.py | 4 +--- tests/async/test_async_debug.py | 4 +++- tests/sync/test_debug.py | 4 +--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/captcha_solver_api/_debug.py b/captcha_solver_api/_debug.py index c53e804..3088d7f 100644 --- a/captcha_solver_api/_debug.py +++ b/captcha_solver_api/_debug.py @@ -86,7 +86,7 @@ def emit(self, message: str) -> None: try: self.logger.debug(f"[{_timestamp()}] [{self.name}] {message}") except Exception: - pass + return def initialized(self, version: str, base_url: str, timeout: Any, polling: Any) -> None: self.emit( @@ -119,7 +119,7 @@ def request_success( f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms):\n{_json(data)}" ) except Exception: - pass + return def request_failure( self, @@ -149,8 +149,7 @@ def request_failure( ) elif invalid_json: response = ( - f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms): " - "body is not valid JSON" + f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms): body is not valid JSON" ) else: response = f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms):\n{_json(data)}" @@ -159,7 +158,7 @@ def request_failure( f"REQUEST (POST {url}):\n{_json(payload)}\n{response}" ) except Exception: - pass + return def solve_summary( self, @@ -191,7 +190,7 @@ def solve_summary( lines.append(f" error: {_error_details(error)}") self.emit("\n".join(lines)) except Exception: - pass + return def _request_context(endpoint: str, payload: Dict[str, Any]) -> str: diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index 5c1f048..b4f99f7 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -30,9 +30,7 @@ image_body = b64encode(image_file.read()).decode("utf-8") with CaptchaClient(api_key, debug=True) as client: - solution = client.solve( - ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6) - ) + solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) # The SOLVE SUMMARY is emitted before solve() returns, so this is printed last. print(f"Recognized text: {solution['text']}") diff --git a/tests/async/test_async_debug.py b/tests/async/test_async_debug.py index 3bcb7fd..ff42350 100644 --- a/tests/async/test_async_debug.py +++ b/tests/async/test_async_debug.py @@ -16,7 +16,9 @@ async def test_async_debug_success_processing_summary_and_masking(): client._debug.logger.debug = Mock() task = ImageToTextTask(body="A" * 300) responses = [ - httpx.Response(200, json={"errorId": 0, "taskId": 9}, request=httpx.Request("POST", "https://x")), + httpx.Response( + 200, json={"errorId": 0, "taskId": 9}, request=httpx.Request("POST", "https://x") + ), httpx.Response( 200, json={"errorId": 0, "status": "processing"}, diff --git a/tests/sync/test_debug.py b/tests/sync/test_debug.py index fb53ed1..91592cf 100644 --- a/tests/sync/test_debug.py +++ b/tests/sync/test_debug.py @@ -51,9 +51,7 @@ def test_success_masks_and_truncates_without_mutating_payload(): "task": {"type": "ImageToTextTask", "body": body}, } client.session.post = Mock( - return_value=response( - data={"errorId": 0, "taskId": 123, "solution": {"token": long_token}} - ) + return_value=response(data={"errorId": 0, "taskId": 123, "solution": {"token": long_token}}) ) result = client._request("createTask", payload) From 77aea698b2bc4ae76d81423db7bca78dba8f5a50 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 16:59:57 +0300 Subject: [PATCH 03/18] fix: resolve strict type checks --- captcha_solver_api/async_client.py | 18 +++++++++--------- captcha_solver_api/client.py | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index e8c6509..3d47d0c 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -142,25 +142,25 @@ async def _request( response = await self._client.post(url, json=payload, timeout=30) response.raise_for_status() except httpx.TimeoutException as exc: - response = getattr(exc, "response", None) + error_response = getattr(exc, "response", None) self._debug.request_failure( endpoint, url, payload, exc, round((time.monotonic() - started) * 1000), - status=getattr(response, "status_code", None), - reason=getattr(response, "reason_phrase", "") or "", - body_missing=response is not None, + status=getattr(error_response, "status_code", None), + reason=getattr(error_response, "reason_phrase", "") or "", + body_missing=error_response is not None, ) raise CaptchaTimeoutError("Request timed out.") from exc except httpx.HTTPError as exc: - response = getattr(exc, "response", None) + error_response = getattr(exc, "response", None) data = None invalid_json = False - if response is not None: + if error_response is not None: try: - data = response.json() + data = error_response.json() except ValueError: invalid_json = True self._debug.request_failure( @@ -169,8 +169,8 @@ async def _request( payload, exc, round((time.monotonic() - started) * 1000), - status=getattr(response, "status_code", None), - reason=getattr(response, "reason_phrase", "") or "", + status=getattr(error_response, "status_code", None), + reason=getattr(error_response, "reason_phrase", "") or "", data=data, invalid_json=invalid_json, ) diff --git a/captcha_solver_api/client.py b/captcha_solver_api/client.py index 82518c2..1e30249 100644 --- a/captcha_solver_api/client.py +++ b/captcha_solver_api/client.py @@ -132,25 +132,25 @@ def _request( response = self.session.post(url, json=payload, timeout=30) response.raise_for_status() except requests.exceptions.Timeout as exc: - response = getattr(exc, "response", None) + error_response = getattr(exc, "response", None) self._debug.request_failure( endpoint, url, payload, exc, round((time.monotonic() - started) * 1000), - status=getattr(response, "status_code", None), - reason=getattr(response, "reason", "") or "", - body_missing=response is not None, + status=getattr(error_response, "status_code", None), + reason=getattr(error_response, "reason", "") or "", + body_missing=error_response is not None, ) raise CaptchaTimeoutError("Request timed out.") from exc except requests.exceptions.RequestException as exc: - response = getattr(exc, "response", None) + error_response = getattr(exc, "response", None) data = None invalid_json = False - if response is not None: + if error_response is not None: try: - data = response.json() + data = error_response.json() except ValueError: invalid_json = True self._debug.request_failure( @@ -159,8 +159,8 @@ def _request( payload, exc, round((time.monotonic() - started) * 1000), - status=getattr(response, "status_code", None), - reason=getattr(response, "reason", "") or "", + status=getattr(error_response, "status_code", None), + reason=getattr(error_response, "reason", "") or "", data=data, invalid_json=invalid_json, ) From 127a7323e8ec72ddcb26d920a84293c0cc0c613c Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 17:22:30 +0300 Subject: [PATCH 04/18] docs: add workflow guides to examples --- examples/async/balance.py | 5 +++++ examples/async/coordinates.py | 6 ++++++ examples/async/geetest_v3_proxy.py | 6 ++++++ examples/async/geetest_v3_proxyless.py | 6 ++++++ examples/async/geetest_v4_proxy.py | 6 ++++++ examples/async/geetest_v4_proxyless.py | 6 ++++++ examples/async/image_to_text.py | 6 ++++++ examples/async/recaptcha_v2_enterprise_proxy.py | 6 ++++++ examples/async/recaptcha_v2_enterprise_proxyless.py | 6 ++++++ examples/async/recaptcha_v2_proxy.py | 6 ++++++ examples/async/recaptcha_v2_proxyless.py | 6 ++++++ examples/async/recaptcha_v3.py | 6 ++++++ examples/async/tencent_proxy.py | 6 ++++++ examples/async/tencent_proxyless.py | 6 ++++++ examples/async/turnstile_proxy.py | 6 ++++++ examples/async/turnstile_proxyless.py | 6 ++++++ examples/async/yandex_smartcaptcha_image.py | 6 ++++++ examples/async/yandex_smartcaptcha_proxy.py | 6 ++++++ examples/async/yandex_smartcaptcha_proxyless.py | 6 ++++++ examples/sync/balance.py | 5 +++++ examples/sync/coordinates.py | 6 ++++++ examples/sync/debug_mode.py | 6 ++++++ examples/sync/geetest_v3_proxy.py | 6 ++++++ examples/sync/geetest_v3_proxyless.py | 6 ++++++ examples/sync/geetest_v4_proxy.py | 6 ++++++ examples/sync/geetest_v4_proxyless.py | 6 ++++++ examples/sync/image_to_text.py | 6 ++++++ examples/sync/recaptcha_v2_enterprise_proxy.py | 6 ++++++ examples/sync/recaptcha_v2_enterprise_proxyless.py | 6 ++++++ examples/sync/recaptcha_v2_proxy.py | 6 ++++++ examples/sync/recaptcha_v2_proxyless.py | 6 ++++++ examples/sync/recaptcha_v3.py | 6 ++++++ examples/sync/tencent_proxy.py | 6 ++++++ examples/sync/tencent_proxyless.py | 6 ++++++ examples/sync/turnstile_proxy.py | 6 ++++++ examples/sync/turnstile_proxyless.py | 6 ++++++ examples/sync/yandex_smartcaptcha_image.py | 6 ++++++ examples/sync/yandex_smartcaptcha_proxy.py | 6 ++++++ examples/sync/yandex_smartcaptcha_proxyless.py | 6 ++++++ 39 files changed, 232 insertions(+) diff --git a/examples/async/balance.py b/examples/async/balance.py index 3c81311..83b21a0 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -1,6 +1,11 @@ """ Example: Get account balance with the async client. +How it works: +STEP-01 - Configure the API key and create AsyncCaptchaClient. +STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. +STEP-03 - Print the returned amount or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Returns the current available balance of your account. diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 70663b6..ec80101 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -1,6 +1,12 @@ """ Example: Solve a click-based image captcha using CoordinatesTask with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. +STEP-02 - Read the image data and create CoordinatesTask without a proxy. +STEP-03 - Await solve(), which creates the task and polls for its solution. +STEP-04 - Print the coordinates to click in the same order, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index ce6bc1e..e4a20f9 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v3 challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. +STEP-02 - Create GeeTestTask with gt and challenge, then await solve() through the proxy. +STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 1d9ffec..ec98b6c 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v3 challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. +STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then await solve(). +STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index 506af84..b49b879 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v4 challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. +STEP-02 - Create GeeTestTask with version 4 and await solve() through the proxy. +STEP-03 - Print the returned v4 fields and explain their site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 5668b8d..9ab50bb 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v4 challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. +STEP-02 - Create GeeTestTaskProxyless with version 4 and await solve(). +STEP-03 - Print the returned v4 fields and explain their site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index db6fb9a..4adeadf 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -1,6 +1,12 @@ """ Example: Solve an image captcha with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. +STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. +STEP-03 - Await solve(), which creates the task and polls for its solution. +STEP-04 - Print the recognized text, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 4389924..2772c94 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. +STEP-02 - Create RecaptchaV2EnterpriseTask and await solve() through that proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index 10d157f..11f6f03 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and extract the Enterprise site key and payload. +STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and await solve() without a customer proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 6cd87d9..68332f5 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 challenge through your own proxy with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. +STEP-02 - Create RecaptchaV2Task and await solve() through that proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index 01d2626..3b55df0 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 challenge without a proxy with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. +STEP-02 - Create RecaptchaV2TaskProxyless and await solve() without a customer proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index d4bb2a7..4c3b3c7 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v3 challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). +STEP-02 - Create RecaptchaV3TaskProxyless with the required score and await solve(). +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, websiteKey, and minScore with values from your target diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index c92644e..3f723a0 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. +STEP-02 - Create TencentTask and await solve() through that proxy. +STEP-03 - Print ticket and randstr and explain their site-specific application. +STEP-04 - Report errors; page or server acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index a840450..bea4556 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. +STEP-02 - Create TencentTaskProxyless and await solve() without a customer proxy. +STEP-03 - Print ticket and randstr and explain their site-specific application. +STEP-04 - Report errors; page or server acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index f46b797..3d7caff 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. +STEP-02 - Create TurnstileTask and await solve() through that proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 76dd7f2..761345f 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and extract the widget key and challenge data. +STEP-02 - Create TurnstileTaskProxyless and await solve() without a customer proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index a89202c..30d1945 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -1,5 +1,11 @@ """Example: Solve an image-based Yandex SmartCaptcha asynchronously. +How it works: +STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge images. +STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. +STEP-03 - Await solve(), which creates the task and polls for its solution. +STEP-04 - Print the ordered coordinates to click, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. The sample captcha and instruction images are bundled in examples/assets/. diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 5cae19b..461384a 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. +STEP-02 - Create YandexSmartCaptchaTask and await solve() through that proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index 9537797..7f6e99c 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +How it works: +STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. +STEP-02 - Create YandexSmartCaptchaTaskProxyless and await solve() without a customer proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index f3a6ae7..f1179ba 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -1,6 +1,11 @@ """ Example: Get account balance. +How it works: +STEP-01 - Configure the API key and create CaptchaClient. +STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. +STEP-03 - Print the returned amount or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Returns the current available balance of your account. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index 59c3421..c6c9993 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -1,6 +1,12 @@ """ Example: Solve a click-based image captcha using CoordinatesTask. +How it works: +STEP-01 - Configure CaptchaClient and locate the bundled images. +STEP-02 - Read the image data and create CoordinatesTask without a proxy. +STEP-03 - Call solve(), which creates the task and polls for its solution. +STEP-04 - Print the coordinates to click in the same order, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index b4f99f7..4de5b1f 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -2,6 +2,12 @@ This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment or in the repository's .env file before running it. + +How it works: +STEP-01 - Read the bundled image and create CaptchaClient with debug enabled. +STEP-02 - Create ImageToTextTask and call solve(). +STEP-03 - Inspect the sanitized debug events and SOLVE SUMMARY. +STEP-04 - Print the recognized text returned by the service. """ import os diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index e91b441..63ba79c 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v3 challenge. +How it works: +STEP-01 - Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. +STEP-02 - Create GeeTestTask with gt and challenge, then call solve() through the proxy. +STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 10503e6..9387042 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v3 challenge. +How it works: +STEP-01 - Configure CaptchaClient and fetch a fresh v3 challenge from the target. +STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then call solve(). +STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index 9d05bdf..00efe64 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v4 challenge. +How it works: +STEP-01 - Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. +STEP-02 - Create GeeTestTask with version 4 and call solve() through the proxy. +STEP-03 - Print the returned v4 fields and explain their site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index 55cb061..8f41894 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a GeeTest v4 challenge. +How it works: +STEP-01 - Configure CaptchaClient and obtain captcha_id from the target's v4 loader. +STEP-02 - Create GeeTestTaskProxyless with version 4 and call solve(). +STEP-03 - Print the returned v4 fields and explain their site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 892d693..315c10f 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -1,6 +1,12 @@ """ Example: Solve an Image to Text challenge. +How it works: +STEP-01 - Configure CaptchaClient and locate the bundled images. +STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. +STEP-03 - Call solve(), which creates the task and polls for its solution. +STEP-04 - Print the recognized text, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index b2e5ba3..a561818 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. +How it works: +STEP-01 - Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. +STEP-02 - Create RecaptchaV2EnterpriseTask and call solve() through that proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index bd7ebc5..44298ad 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. +How it works: +STEP-01 - Configure CaptchaClient and extract the Enterprise site key and payload. +STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and call solve() without a customer proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 40f6674..28c3364 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 challenge. +How it works: +STEP-01 - Configure CaptchaClient, page parameters, and customer proxy credentials. +STEP-02 - Create RecaptchaV2Task and call solve() through that proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index 2670021..d4bb8f8 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 challenge. +How it works: +STEP-01 - Configure CaptchaClient and obtain the page URL and data-sitekey. +STEP-02 - Create RecaptchaV2TaskProxyless and call solve() without a customer proxy. +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index cd2164b..cd8c26e 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v3 challenge. +How it works: +STEP-01 - Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). +STEP-02 - Create RecaptchaV3TaskProxyless with the required score and call solve(). +STEP-03 - Print gRecaptchaResponse and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, websiteKey, and minScore with values from your target diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 1314907..0c62c50 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge. +How it works: +STEP-01 - Configure CaptchaClient, Tencent parameters, and customer proxy credentials. +STEP-02 - Create TencentTask and call solve() through that proxy. +STEP-03 - Print ticket and randstr and explain their site-specific application. +STEP-04 - Report errors; page or server acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index fd620bc..5d84288 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge. +How it works: +STEP-01 - Configure CaptchaClient and obtain appId from the target page's Tencent setup. +STEP-02 - Create TencentTaskProxyless and call solve() without a customer proxy. +STEP-03 - Print ticket and randstr and explain their site-specific application. +STEP-04 - Report errors; page or server acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 29d61ac..2798dee 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Cloudflare Turnstile challenge. +How it works: +STEP-01 - Configure CaptchaClient, widget parameters, and customer proxy credentials. +STEP-02 - Create TurnstileTask and call solve() through that proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 258402d..d0e2d98 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Cloudflare Turnstile challenge. +How it works: +STEP-01 - Configure CaptchaClient and extract the widget key and optional challenge data. +STEP-02 - Create TurnstileTaskProxyless and call solve() without a customer proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 9973cdc..bc771aa 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -1,5 +1,11 @@ """Example: Solve an image-based Yandex SmartCaptcha. +How it works: +STEP-01 - Configure CaptchaClient and locate the bundled challenge images. +STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. +STEP-03 - Call solve(), which creates the task and polls for its solution. +STEP-04 - Print the ordered coordinates to click, or report the error. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. The sample captcha and instruction images are bundled in examples/assets/. diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 08a2fc5..1ec0a7c 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). +How it works: +STEP-01 - Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. +STEP-02 - Create YandexSmartCaptchaTask and call solve() through that proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index af1b089..0e8b00a 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). +How it works: +STEP-01 - Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. +STEP-02 - Create YandexSmartCaptchaTaskProxyless and call solve() without a customer proxy. +STEP-03 - Print the token and explain its site-specific application. +STEP-04 - Report errors; page acceptance must be verified by the integration. + Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. From e9f514ae054591cd3c0f9c38ef6713fbf303e0a0 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 17:29:19 +0300 Subject: [PATCH 05/18] docs: align step comments across examples --- examples/async/balance.py | 3 +++ examples/async/coordinates.py | 4 ++++ examples/async/geetest_v3_proxy.py | 4 ++++ examples/async/geetest_v3_proxyless.py | 4 ++++ examples/async/geetest_v4_proxy.py | 4 ++++ examples/async/geetest_v4_proxyless.py | 4 ++++ examples/async/image_to_text.py | 4 ++++ examples/async/recaptcha_v2_enterprise_proxy.py | 4 ++++ examples/async/recaptcha_v2_enterprise_proxyless.py | 4 ++++ examples/async/recaptcha_v2_proxy.py | 4 ++++ examples/async/recaptcha_v2_proxyless.py | 4 ++++ examples/async/recaptcha_v3.py | 4 ++++ examples/async/tencent_proxy.py | 4 ++++ examples/async/tencent_proxyless.py | 4 ++++ examples/async/turnstile_proxy.py | 4 ++++ examples/async/turnstile_proxyless.py | 4 ++++ examples/async/yandex_smartcaptcha_image.py | 4 ++++ examples/async/yandex_smartcaptcha_proxy.py | 4 ++++ examples/async/yandex_smartcaptcha_proxyless.py | 4 ++++ examples/sync/balance.py | 3 +++ examples/sync/coordinates.py | 4 ++++ examples/sync/debug_mode.py | 4 ++++ examples/sync/geetest_v3_proxy.py | 4 ++++ examples/sync/geetest_v3_proxyless.py | 4 ++++ examples/sync/geetest_v4_proxy.py | 4 ++++ examples/sync/geetest_v4_proxyless.py | 4 ++++ examples/sync/image_to_text.py | 4 ++++ examples/sync/recaptcha_v2_enterprise_proxy.py | 4 ++++ examples/sync/recaptcha_v2_enterprise_proxyless.py | 4 ++++ examples/sync/recaptcha_v2_proxy.py | 4 ++++ examples/sync/recaptcha_v2_proxyless.py | 4 ++++ examples/sync/recaptcha_v3.py | 4 ++++ examples/sync/tencent_proxy.py | 4 ++++ examples/sync/tencent_proxyless.py | 4 ++++ examples/sync/turnstile_proxy.py | 4 ++++ examples/sync/turnstile_proxyless.py | 4 ++++ examples/sync/yandex_smartcaptcha_image.py | 4 ++++ examples/sync/yandex_smartcaptcha_proxy.py | 4 ++++ examples/sync/yandex_smartcaptcha_proxyless.py | 4 ++++ 39 files changed, 154 insertions(+) diff --git a/examples/async/balance.py b/examples/async/balance.py index 83b21a0..7eac15f 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -35,15 +35,18 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure the API key and create AsyncCaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): async with AsyncCaptchaClient(api_key) as solver: + # STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. # Get the current account balance. # Returns a float with the available amount in your account currency. try: balance = await solver.get_balance() + # STEP-03: Print the returned amount or report the error. print("Balance: " + str(balance)) except Exception as e: sys.exit(e) diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index ec80101..1e2851b 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -39,16 +39,19 @@ async def main(): + # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. async with AsyncCaptchaClient(api_key) as solver: # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. try: + # STEP-02: Read the image data and create CoordinatesTask without a proxy. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "fruit-click.png"), "rb") as f: body = b64encode(f.read()).decode("utf-8") + # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( CoordinatesTask( body=body, # Base64-encoded captcha image (required) @@ -57,6 +60,7 @@ async def main(): ) # Solution contains {"coordinates": [{"x": 140, "y": 110}]} # Click on each coordinate in order. Coordinates are pixel positions. + # STEP-04: Print the coordinates to click in the same order, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index e4a20f9..ae73457 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -39,6 +39,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask +# STEP-01: Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -60,6 +61,7 @@ async def main(): # --- With proxy example --- # Solves GeeTest v3 through your own proxy. try: + # STEP-02: Create GeeTestTask with gt and challenge, then await solve() through the proxy. result = await solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -73,8 +75,10 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index ec98b6c..2d0c31e 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -39,6 +39,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -61,6 +62,7 @@ async def main(): # Solves GeeTest v3 without a proxy. # v3 is the default version, so the version field can be omitted. try: + # STEP-02: Create GeeTestTaskProxyless with gt and challenge, then await solve(). result = await solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -72,10 +74,12 @@ async def main(): # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) + # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. # Solution contains {"challenge": "...", "validate": "...", "seccode": "..."} # Pass solution.validate and solution.seccode to the page's GeeTest callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index b49b879..df806dd 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -34,6 +34,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask +# STEP-01: Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -43,6 +44,7 @@ async def main(): # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: + # STEP-02: Create GeeTestTask with version 4 and await solve() through the proxy. result = await solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -58,8 +60,10 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print the returned v4 fields and explain their site-specific application. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 9ab50bb..4948c92 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -34,6 +34,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -44,6 +45,7 @@ async def main(): # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. try: + # STEP-02: Create GeeTestTaskProxyless with version 4 and await solve(). result = await solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -55,10 +57,12 @@ async def main(): # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) + # STEP-03: Print the returned v4 fields and explain their site-specific application. # Solution contains {"captcha_id": "...", "lot_number": "...", "pass_token": "...", "gen_time": "...", "captcha_output": "..."} # Pass these values together into the page's GeeTest v4 callback as-is. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 4adeadf..6b42dd1 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -46,6 +46,7 @@ def encode_image(filename): async def main(): + # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. # Image to Text tasks are usually fast. Default timeout is fine. async with AsyncCaptchaClient(api_key) as solver: digits_body = encode_image("captcha-digits.png") @@ -54,6 +55,8 @@ async def main(): # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) # with character set hints. try: + # STEP-02: Read an image as Base64 and create ImageToTextTask with answer hints. + # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( ImageToTextTask( body=digits_body, # Base64-encoded image (required) @@ -64,6 +67,7 @@ async def main(): ) # Solution contains {"text": "58204"} # Submit solution.text to the target form field. + # STEP-04: Print the recognized text, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 2772c94..c9da34c 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask +# STEP-01: Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -41,6 +42,7 @@ async def main(): # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: + # STEP-02: Create RecaptchaV2EnterpriseTask and await solve() through that proxy. result = await solver.solve( RecaptchaV2EnterpriseTask( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -58,9 +60,11 @@ async def main(): cookies="foo=bar; baz=1", # Session cookies if needed ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index 11f6f03..06b866e 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -43,6 +44,7 @@ async def main(): # If the site passes extra parameters to grecaptcha.enterprise.render(), # you must pass them as enterprisePayload or the token will be rejected. try: + # STEP-02: Create RecaptchaV2EnterpriseTaskProxyless and await solve() without a customer proxy. result = await solver.solve( RecaptchaV2EnterpriseTaskProxyless( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -55,10 +57,12 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 68332f5..09d0075 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2Task +# STEP-01: Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -43,6 +44,7 @@ async def main(): # Solves reCAPTCHA v2 through your own proxy. # Use when the target site is geo-restricted or you need session consistency. try: + # STEP-02: Create RecaptchaV2Task and await solve() through that proxy. result = await solver.solve( RecaptchaV2Task( websiteURL="https://example.com/login", # Full URL of the page with captcha @@ -55,9 +57,11 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index 3b55df0..b6e7234 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -31,6 +31,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2TaskProxyless +# STEP-01: Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -41,6 +42,7 @@ async def main(): # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. The service uses its own IP addresses. try: + # STEP-02: Create RecaptchaV2TaskProxyless and await solve() without a customer proxy. # solve() handles task creation, polling, and returns the solution dict. result = await solver.solve( RecaptchaV2TaskProxyless( @@ -49,10 +51,12 @@ async def main(): isInvisible=False, # Set True for invisible reCAPTCHA ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index 4c3b3c7..75a054c 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -33,6 +33,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV3TaskProxyless +# STEP-01: Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -43,6 +44,7 @@ async def main(): # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). try: + # STEP-02: Create RecaptchaV3TaskProxyless with the required score and await solve(). result = await solver.solve( RecaptchaV3TaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the v3 widget @@ -54,10 +56,12 @@ async def main(): # apiDomain='www.recaptcha.net', # Set if site loads from recaptcha.net ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or grecaptcha callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index 3f723a0..35b72ed 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTask +# STEP-01: Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -41,6 +42,7 @@ async def main(): # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: + # STEP-02: Create TencentTask and await solve() through that proxy. result = await solver.solve( TencentTask( websiteURL="https://example.com/register", # Full URL of the page with captcha @@ -54,9 +56,11 @@ async def main(): captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", ) ) + # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains the same appid, ret, ticket, and randstr values. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index bea4556..e4f7226 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -42,6 +43,7 @@ async def main(): # The service's own proxies are used to solve the captcha. # appId is found in the page source code. captchaScript is optional if the site uses the default. try: + # STEP-02: Create TencentTaskProxyless and await solve() without a customer proxy. result = await solver.solve( TencentTaskProxyless( websiteURL="https://example.com/register", # Full URL of the page using Tencent captcha @@ -50,10 +52,12 @@ async def main(): captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", # Custom script URL if non-default ) ) + # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains {"appid": "...", "ret": 0, "ticket": "...", "randstr": "..."} # Pass all four values together into the page's captcha callback as-is. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index 3d7caff..584b511 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTask +# STEP-01: Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -40,6 +41,7 @@ async def main(): # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: + # STEP-02: Create TurnstileTask and await solve() through that proxy. result = await solver.solve( TurnstileTask( websiteURL="https://example.com/login", # Full URL of the page with Turnstile @@ -57,8 +59,10 @@ async def main(): # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', ) ) + # STEP-03: Print the token and explain its site-specific application. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 761345f..fa46ef0 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -32,6 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and extract the widget key and challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -42,6 +43,7 @@ async def main(): # The token is tied to the User-Agent. If you pass userAgent, use the same # User-Agent in your browser or bot when submitting the token. try: + # STEP-02: Create TurnstileTaskProxyless and await solve() without a customer proxy. result = await solver.solve( TurnstileTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with a Turnstile widget @@ -53,10 +55,12 @@ async def main(): # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', # Must match the browser submitting the token ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "0.zxcv..."} # Pass this token to the widget callback or cf-turnstile-response field. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index 30d1945..276ce51 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -40,14 +40,18 @@ def encode_image(filename: str) -> str: async def main() -> None: + # STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async with AsyncCaptchaClient(api_key) as solver: + # STEP-02: Encode both images and create YandexSmartCaptchaImageTask. + # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), imgInstructions=encode_image("yandex-smartcaptcha-instructions.png"), ) ) + # STEP-04: Print the ordered coordinates to click, or report the error. # Click the returned points on the captcha image in the listed order. # Example: {"coordinates": [{"x": 73, "y": 92}, ...]} print("result: " + str(result)) diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 461384a..3bbbef0 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -31,6 +31,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask +# STEP-01: Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -40,6 +41,7 @@ async def main(): # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. try: + # STEP-02: Create YandexSmartCaptchaTask and await solve() through that proxy. result = await solver.solve( YandexSmartCaptchaTask( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -55,9 +57,11 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains the same token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index 7f6e99c..ac32a85 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -31,6 +31,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless +# STEP-01: Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -41,6 +42,7 @@ async def main(): # The service's own proxies are used to solve the captcha. # websiteKey is the sitekey value from the page code or captcha iframe. try: + # STEP-02: Create YandexSmartCaptchaTaskProxyless and await solve() without a customer proxy. result = await solver.solve( YandexSmartCaptchaTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -50,10 +52,12 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "dV9xNjYyNTU3NjkxO4k9OTQuNVMuMjkuMjM9..."} # Use solution.token in the smart-token field or pass to your site's backend. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/balance.py b/examples/sync/balance.py index f1179ba..eec7f6c 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -34,15 +34,18 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure the API key and create CaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. solver = CaptchaClient(api_key) +# STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. # Get the current account balance. # Returns a float with the available amount in your account currency. try: balance = solver.get_balance() + # STEP-03: Print the returned amount or report the error. print("Balance: " + str(balance)) except Exception as e: sys.exit(e) diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index c6c9993..c46192b 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -40,6 +40,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -49,11 +50,13 @@ # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. try: + # STEP-02: Read the image data and create CoordinatesTask without a proxy. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "fruit-click.png"), "rb") as f: body = b64encode(f.read()).decode("utf-8") + # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( CoordinatesTask( body=body, # Base64-encoded captcha image (required) @@ -62,6 +65,7 @@ ) # Solution contains {"coordinates": [{"x": 140, "y": 110}]} # Click on each coordinate in order. Coordinates are pixel positions. + # STEP-04: Print the coordinates to click in the same order, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index 4de5b1f..9d2aab0 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -29,6 +29,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import ImageToTextTask +# STEP-01: Read the bundled image and create CaptchaClient with debug enabled. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") @@ -36,7 +37,10 @@ image_body = b64encode(image_file.read()).decode("utf-8") with CaptchaClient(api_key, debug=True) as client: + # STEP-02: Create ImageToTextTask and call solve(). solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) +# STEP-03: Inspect the sanitized debug events and SOLVE SUMMARY. +# STEP-04: Print the recognized text returned by the service. # The SOLVE SUMMARY is emitted before solve() returns, so this is printed last. print(f"Recognized text: {solution['text']}") diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index 63ba79c..d7ad3d9 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -44,6 +44,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -64,6 +65,7 @@ # --- With proxy example --- # Solves GeeTest v3 through your own proxy. try: + # STEP-02: Create GeeTestTask with gt and challenge, then call solve() through the proxy. result = solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -77,6 +79,8 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 9387042..11d4c50 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -44,6 +44,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -65,6 +66,7 @@ # Solves GeeTest v3 without a proxy. # v3 is the default version, so the version field can be omitted. try: + # STEP-02: Create GeeTestTaskProxyless with gt and challenge, then call solve(). result = solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -76,8 +78,10 @@ # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) + # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. # Solution contains {"challenge": "...", "validate": "...", "seccode": "..."} # Pass solution.validate and solution.seccode to the page's GeeTest callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index 00efe64..155e9f8 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -39,6 +39,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -48,6 +49,7 @@ # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: + # STEP-02: Create GeeTestTask with version 4 and call solve() through the proxy. result = solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -63,6 +65,8 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print the returned v4 fields and explain their site-specific application. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index 8f41894..68a9571 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -39,6 +39,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -49,6 +50,7 @@ # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. try: + # STEP-02: Create GeeTestTaskProxyless with version 4 and call solve(). result = solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -60,8 +62,10 @@ # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) + # STEP-03: Print the returned v4 fields and explain their site-specific application. # Solution contains {"captcha_id": "...", "lot_number": "...", "pass_token": "...", "gen_time": "...", "captcha_output": "..."} # Pass these values together into the page's GeeTest v4 callback as-is. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 315c10f..6ba3cf9 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -39,6 +39,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -49,11 +50,13 @@ # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) # with character set hints. try: + # STEP-02: Read an image as Base64 and create ImageToTextTask with answer hints. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "captcha-digits.png"), "rb") as f: digits_body = b64encode(f.read()).decode("utf-8") + # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( ImageToTextTask( body=digits_body, # Base64-encoded image (required) @@ -64,6 +67,7 @@ ) # Solution contains {"text": "58204"} # Submit solution.text to the target form field. + # STEP-04: Print the recognized text, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index a561818..bf402a4 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -37,6 +37,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -46,6 +47,7 @@ # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: + # STEP-02: Create RecaptchaV2EnterpriseTask and call solve() through that proxy. result = solver.solve( RecaptchaV2EnterpriseTask( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -63,7 +65,9 @@ cookies="foo=bar; baz=1", # Session cookies if needed ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index 44298ad..9c077a5 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -37,6 +37,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -48,6 +49,7 @@ # If the site passes extra parameters to grecaptcha.enterprise.render(), # you must pass them as enterprisePayload or the token will be rejected. try: + # STEP-02: Create RecaptchaV2EnterpriseTaskProxyless and call solve() without a customer proxy. result = solver.solve( RecaptchaV2EnterpriseTaskProxyless( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -60,8 +62,10 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 28c3364..84b3de7 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -36,6 +36,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -47,6 +48,7 @@ # Solves reCAPTCHA v2 through your own proxy. # Required when the target site is geo-restricted or you need session consistency. try: + # STEP-02: Create RecaptchaV2Task and call solve() through that proxy. result = solver.solve( RecaptchaV2Task( websiteURL="https://example.com/login", # Full URL of the page with captcha @@ -59,7 +61,9 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index d4bb8f8..5956e98 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -36,6 +36,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -47,6 +48,7 @@ # Solves reCAPTCHA v2 without a proxy. # The service uses its own IP addresses. try: + # STEP-02: Create RecaptchaV2TaskProxyless and call solve() without a customer proxy. # Create a task and wait for the solution. # solve() handles task creation, polling, and returns the solution dict. result = solver.solve( @@ -56,8 +58,10 @@ isInvisible=False, # Set True for invisible reCAPTCHA ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index cd8c26e..e5769e0 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -38,6 +38,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -48,6 +49,7 @@ # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). try: + # STEP-02: Create RecaptchaV3TaskProxyless with the required score and call solve(). result = solver.solve( RecaptchaV3TaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the v3 widget @@ -59,8 +61,10 @@ # apiDomain='www.recaptcha.net', # Set if site loads from recaptcha.net ) ) + # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or grecaptcha callback. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 0c62c50..505ca73 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -31,6 +31,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTask +# STEP-01: Configure CaptchaClient, Tencent parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") solver = CaptchaClient(api_key) @@ -39,6 +40,7 @@ # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: + # STEP-02: Create TencentTask and call solve() through that proxy. result = solver.solve( TencentTask( websiteURL="https://example.com/register", # Full URL of the page with captcha @@ -52,7 +54,9 @@ captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", ) ) + # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains the same appid, ret, ticket, and randstr values. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 5d84288..85b32d4 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -31,6 +31,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless +# STEP-01: Configure CaptchaClient and obtain appId from the target page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") solver = CaptchaClient(api_key) @@ -40,6 +41,7 @@ # The service's own proxies are used to solve the captcha. # appId is found in the page source code. captchaScript is optional if the site uses the default. try: + # STEP-02: Create TencentTaskProxyless and call solve() without a customer proxy. result = solver.solve( TencentTaskProxyless( websiteURL="https://example.com/register", # Full URL of the page using Tencent captcha @@ -48,8 +50,10 @@ captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", # Custom script URL if non-default ) ) + # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains {"appid": "...", "ret": 0, "ticket": "...", "randstr": "..."} # Pass all four values together into the page's captcha callback as-is. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 2798dee..071310f 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -37,6 +37,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -45,6 +46,7 @@ # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: + # STEP-02: Create TurnstileTask and call solve() through that proxy. result = solver.solve( TurnstileTask( websiteURL="https://example.com/login", # Full URL of the page with Turnstile @@ -62,6 +64,8 @@ # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', ) ) + # STEP-03: Print the token and explain its site-specific application. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index d0e2d98..2b20421 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -37,6 +37,7 @@ # you can just set the API key directly to its value like: # api_key="1abc234de56fab7c89012d34e56fa7b8" +# STEP-01: Configure CaptchaClient and extract the widget key and optional challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. @@ -47,6 +48,7 @@ # The token is tied to the User-Agent. If you pass userAgent, use the same # User-Agent in your browser or bot when submitting the token. try: + # STEP-02: Create TurnstileTaskProxyless and call solve() without a customer proxy. result = solver.solve( TurnstileTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with a Turnstile widget @@ -58,8 +60,10 @@ # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', # Must match the browser submitting the token ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "0.zxcv..."} # Pass this token to the widget callback or cf-turnstile-response field. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index bc771aa..7a9cb97 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -38,16 +38,20 @@ def encode_image(filename: str) -> str: return b64encode(image_file.read()).decode("utf-8") +# STEP-01: Configure CaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") solver = CaptchaClient(api_key) +# STEP-02: Encode both images and create YandexSmartCaptchaImageTask. try: + # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), imgInstructions=encode_image("yandex-smartcaptcha-instructions.png"), ) ) + # STEP-04: Print the ordered coordinates to click, or report the error. # Click the returned points on the captcha image in the listed order. # Example: {"coordinates": [{"x": 73, "y": 92}, ...]} print("result: " + str(result)) diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 1ec0a7c..6b37dc6 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -30,6 +30,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask +# STEP-01: Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") solver = CaptchaClient(api_key) @@ -38,6 +39,7 @@ # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. try: + # STEP-02: Create YandexSmartCaptchaTask and call solve() through that proxy. result = solver.solve( YandexSmartCaptchaTask( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -53,7 +55,9 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains the same token. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index 0e8b00a..bc6f67f 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -30,6 +30,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless +# STEP-01: Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") solver = CaptchaClient(api_key) @@ -39,6 +40,7 @@ # The service's own proxies are used to solve the captcha. # websiteKey is the sitekey value from the page code or captcha iframe. try: + # STEP-02: Create YandexSmartCaptchaTaskProxyless and call solve() without a customer proxy. result = solver.solve( YandexSmartCaptchaTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -48,8 +50,10 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) + # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "dV9xNjYyNTU3NjkxO4k9OTQuNVMuMjkuMjM9..."} # Use solution.token in the smart-token field or pass to your site's backend. print("result: " + str(result)) except Exception as e: + # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) From 838a8bb825cfafcf7e65f742a88f6cce8b631d3f Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 17:49:31 +0300 Subject: [PATCH 06/18] docs: expand example descriptions --- examples/async/balance.py | 4 ++++ examples/async/coordinates.py | 5 +++++ examples/async/geetest_v3_proxy.py | 5 +++++ examples/async/geetest_v3_proxyless.py | 5 +++++ examples/async/geetest_v4_proxy.py | 5 +++++ examples/async/geetest_v4_proxyless.py | 5 +++++ examples/async/image_to_text.py | 4 ++++ examples/async/recaptcha_v2_enterprise_proxy.py | 5 +++++ examples/async/recaptcha_v2_enterprise_proxyless.py | 6 ++++++ examples/async/recaptcha_v2_proxy.py | 5 +++++ examples/async/recaptcha_v2_proxyless.py | 5 +++++ examples/async/recaptcha_v3.py | 5 +++++ examples/async/tencent_proxy.py | 6 ++++++ examples/async/tencent_proxyless.py | 5 +++++ examples/async/turnstile_proxy.py | 5 +++++ examples/async/turnstile_proxyless.py | 5 +++++ examples/async/yandex_smartcaptcha_image.py | 5 +++++ examples/async/yandex_smartcaptcha_proxy.py | 5 +++++ examples/async/yandex_smartcaptcha_proxyless.py | 5 +++++ examples/sync/balance.py | 4 ++++ examples/sync/coordinates.py | 5 +++++ examples/sync/debug_mode.py | 5 +++++ examples/sync/geetest_v3_proxy.py | 5 +++++ examples/sync/geetest_v3_proxyless.py | 5 +++++ examples/sync/geetest_v4_proxy.py | 5 +++++ examples/sync/geetest_v4_proxyless.py | 5 +++++ examples/sync/image_to_text.py | 4 ++++ examples/sync/recaptcha_v2_enterprise_proxy.py | 5 +++++ examples/sync/recaptcha_v2_enterprise_proxyless.py | 6 ++++++ examples/sync/recaptcha_v2_proxy.py | 5 +++++ examples/sync/recaptcha_v2_proxyless.py | 5 +++++ examples/sync/recaptcha_v3.py | 5 +++++ examples/sync/tencent_proxy.py | 6 ++++++ examples/sync/tencent_proxyless.py | 5 +++++ examples/sync/turnstile_proxy.py | 5 +++++ examples/sync/turnstile_proxyless.py | 5 +++++ examples/sync/yandex_smartcaptcha_image.py | 5 +++++ examples/sync/yandex_smartcaptcha_proxy.py | 5 +++++ examples/sync/yandex_smartcaptcha_proxyless.py | 5 +++++ 39 files changed, 195 insertions(+) diff --git a/examples/async/balance.py b/examples/async/balance.py index 7eac15f..1b67280 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -1,6 +1,10 @@ """ Example: Get account balance with the async client. +This example creates AsyncCaptchaClient, requests the current account balance +without creating a CAPTCHA task, and prints the returned amount. It uses +AsyncCaptchaClient.get_balance(). + How it works: STEP-01 - Configure the API key and create AsyncCaptchaClient. STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 1e2851b..54a62bb 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -1,6 +1,11 @@ """ Example: Solve a click-based image captcha using CoordinatesTask with the async client. +This example reads local challenge and instruction images, encodes them as +Base64, describes what the worker should click, and prints the ordered +coordinates returned by the service. No proxy or target page is involved. It +uses CoordinatesTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. STEP-02 - Read the image data and create CoordinatesTask without a proxy. diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index ae73457..8ea9804 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v3 challenge with the async client. +This example solves GeeTest v3 through your own proxy. Obtain gt, fetch a fresh +challenge for every task, and supply the proxy details; the returned challenge, +validate, and seccode fields must be submitted and verified by the target. It +uses GeeTestTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. STEP-02 - Create GeeTestTask with gt and challenge, then await solve() through the proxy. diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 2d0c31e..2f2ae34 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v3 challenge with the async client. +This example solves GeeTest v3 without a customer proxy. Obtain gt from the +widget and fetch a fresh, session-specific challenge from the target for every +task; the service returns challenge, validate, and seccode for the target's +site-specific callback. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then await solve(). diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index df806dd..ab8a888 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v4 challenge with the async client. +This example solves GeeTest v4 through your own proxy. Obtain captcha_id from +the target's v4 loader, pass it in initParameters, and supply the proxy details; +the returned v4 fields require site-specific submission and verification. It +uses GeeTestTask with version 4 and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. STEP-02 - Create GeeTestTask with version 4 and await solve() through the proxy. diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 4948c92..8c5d9a6 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v4 challenge with the async client. +This example solves GeeTest v4 without a customer proxy. Obtain captcha_id from +the target's v4 loader and pass it in initParameters; the returned v4 fields +must be applied and verified through the target's own flow. It uses +GeeTestTaskProxyless with version 4 and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. STEP-02 - Create GeeTestTaskProxyless with version 4 and await solve(). diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 6b42dd1..3b8bbef 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -1,6 +1,10 @@ """ Example: Solve an image captcha with the async client. +This example reads bundled CAPTCHA images as Base64, adds optional answer-format +hints, sends each image directly to the service without a proxy, and prints the +recognized text. It uses ImageToTextTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index c9da34c..217e85a 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +This example solves reCAPTCHA v2 Enterprise through your own proxy. Supply the +page URL, Enterprise key and payload, and proxy details; the returned +gRecaptchaResponse must be submitted and verified by the target integration. +It uses RecaptchaV2EnterpriseTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. STEP-02 - Create RecaptchaV2EnterpriseTask and await solve() through that proxy. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index 06b866e..d24d547 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +This example solves reCAPTCHA v2 Enterprise without a customer proxy. Supply +the page URL, Enterprise site key, and enterprisePayload when the page passes +one to grecaptcha.enterprise.render(); the returned gRecaptchaResponse still +requires site-specific submission and verification. It uses +RecaptchaV2EnterpriseTaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and extract the Enterprise site key and payload. STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and await solve() without a customer proxy. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 09d0075..b81a2cd 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 challenge through your own proxy with the async client. +This example solves reCAPTCHA v2 through your own proxy. Supply the page URL, +widget data-sitekey, and proxy connection details; the service returns +gRecaptchaResponse for site-specific submission and verification. It uses +RecaptchaV2Task and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. STEP-02 - Create RecaptchaV2Task and await solve() through that proxy. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index b6e7234..dc1b024 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 challenge without a proxy with the async client. +This example solves reCAPTCHA v2 without a customer proxy. Supply the target +page URL and the widget's data-sitekey; the service returns +gRecaptchaResponse, which your integration must submit and verify using the +page-specific flow. It uses RecaptchaV2TaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. STEP-02 - Create RecaptchaV2TaskProxyless and await solve() without a customer proxy. diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index 75a054c..edabeee 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v3 challenge with the async client. +This example solves score-based reCAPTCHA v3 without a customer proxy. Extract +the site key and page action from grecaptcha.execute(), choose the required +minimum score, and submit the returned gRecaptchaResponse through the target's +own flow. It uses RecaptchaV3TaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). STEP-02 - Create RecaptchaV3TaskProxyless with the required score and await solve(). diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index 35b72ed..520d391 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge with the async client. +This example solves Tencent CAPTCHA through your own proxy. Obtain appId and any +custom captchaScript from the target page, provide the proxy details, and pass +the returned ticket and randstr to the page-specific callback. It uses +TencentTask and AsyncCaptchaClient.solve(); callback delivery alone is not proof +of server-side acceptance. + How it works: STEP-01 - Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. STEP-02 - Create TencentTask and await solve() through that proxy. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index e4f7226..f56eb34 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Tencent captcha challenge with the async client. +This example solves Tencent CAPTCHA without a customer proxy. Obtain appId and +any custom captchaScript from the target page, then deliver the returned ticket +and randstr to its registered callback and verify acceptance separately. It uses +TencentTaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. STEP-02 - Create TencentTaskProxyless and await solve() without a customer proxy. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index 584b511..296cd9e 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. +This example solves a Turnstile widget through your own proxy. Supply the page +and widget parameters together with proxy connection details, then apply and +verify the returned token using the target page's own callback or form flow. It +uses TurnstileTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. STEP-02 - Create TurnstileTask and await solve() through that proxy. diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index fa46ef0..064c069 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. +This example solves a Turnstile widget without a customer proxy. Supply the +page URL and data-sitekey plus action, data, pagedata, and matching User-Agent +when the page uses them; then apply the returned token through the page-specific +callback or field. It uses TurnstileTaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and extract the widget key and challenge data. STEP-02 - Create TurnstileTaskProxyless and await solve() without a customer proxy. diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index 276ce51..5ce1972 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -1,5 +1,10 @@ """Example: Solve an image-based Yandex SmartCaptcha asynchronously. +This example reads a local Yandex SmartCaptcha image and its instruction image, +encodes both as Base64, sends them directly without a proxy, and prints the +ordered click coordinates. It uses YandexSmartCaptchaImageTask and +AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge images. STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 3bbbef0..f824b8a 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +This example solves token-based Yandex SmartCaptcha through your own proxy. +Supply the page URL, sitekey, and proxy details; then submit and verify the +returned token through the target's site-specific flow. It uses +YandexSmartCaptchaTask and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. STEP-02 - Create YandexSmartCaptchaTask and await solve() through that proxy. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index ac32a85..0fd950e 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +This example solves token-based Yandex SmartCaptcha without a customer proxy. +Supply the target page URL and sitekey from its widget or iframe; the returned +token must be submitted through the page's smart-token or backend flow and then +verified there. It uses YandexSmartCaptchaTaskProxyless and AsyncCaptchaClient.solve(). + How it works: STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. STEP-02 - Create YandexSmartCaptchaTaskProxyless and await solve() without a customer proxy. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index eec7f6c..85c26a3 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -1,6 +1,10 @@ """ Example: Get account balance. +This example creates CaptchaClient, requests the current account balance without +creating a CAPTCHA task, and prints the returned amount. It uses +CaptchaClient.get_balance(). + How it works: STEP-01 - Configure the API key and create CaptchaClient. STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index c46192b..412a878 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -1,6 +1,11 @@ """ Example: Solve a click-based image captcha using CoordinatesTask. +This example reads local challenge and instruction images, encodes them as +Base64, describes what the worker should click, and prints the ordered +coordinates returned by the service. No proxy or target page is involved. It +uses CoordinatesTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and locate the bundled images. STEP-02 - Read the image data and create CoordinatesTask without a proxy. diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index 9d2aab0..4412fe1 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -1,5 +1,10 @@ """Run one Image to Text task with sanitized debug logging enabled. +This example reads a bundled image as Base64, enables the SDK's opt-in debug +mode, solves the image task, and prints the recognized text after the sanitized +request/response events and SOLVE SUMMARY. It uses ImageToTextTask and +CaptchaClient.solve(). + This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment or in the repository's .env file before running it. diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index d7ad3d9..9d9b116 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v3 challenge. +This example solves GeeTest v3 through your own proxy. Obtain gt, fetch a fresh +challenge for every task, and supply the proxy details; the returned challenge, +validate, and seccode fields must be submitted and verified by the target. It +uses GeeTestTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. STEP-02 - Create GeeTestTask with gt and challenge, then call solve() through the proxy. diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 11d4c50..bbbfed4 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v3 challenge. +This example solves GeeTest v3 without a customer proxy. Obtain gt from the +widget and fetch a fresh, session-specific challenge from the target for every +task; the service returns challenge, validate, and seccode for the target's +site-specific callback. It uses GeeTestTaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and fetch a fresh v3 challenge from the target. STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then call solve(). diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index 155e9f8..edbbd96 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v4 challenge. +This example solves GeeTest v4 through your own proxy. Obtain captcha_id from +the target's v4 loader, pass it in initParameters, and supply the proxy details; +the returned v4 fields require site-specific submission and verification. It +uses GeeTestTask with version 4 and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. STEP-02 - Create GeeTestTask with version 4 and call solve() through the proxy. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index 68a9571..b04c893 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a GeeTest v4 challenge. +This example solves GeeTest v4 without a customer proxy. Obtain captcha_id from +the target's v4 loader and pass it in initParameters; the returned v4 fields +must be applied and verified through the target's own flow. It uses +GeeTestTaskProxyless with version 4 and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and obtain captcha_id from the target's v4 loader. STEP-02 - Create GeeTestTaskProxyless with version 4 and call solve(). diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 6ba3cf9..3af5ccc 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -1,6 +1,10 @@ """ Example: Solve an Image to Text challenge. +This example reads bundled CAPTCHA images as Base64, adds optional answer-format +hints, sends each image directly to the service without a proxy, and prints the +recognized text. It uses ImageToTextTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and locate the bundled images. STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index bf402a4..dcf978e 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. +This example solves reCAPTCHA v2 Enterprise through your own proxy. Supply the +page URL, Enterprise key and payload, and proxy details; the returned +gRecaptchaResponse must be submitted and verified by the target integration. +It uses RecaptchaV2EnterpriseTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. STEP-02 - Create RecaptchaV2EnterpriseTask and call solve() through that proxy. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index 9c077a5..e3a67ae 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -1,6 +1,12 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. +This example solves reCAPTCHA v2 Enterprise without a customer proxy. Supply +the page URL, Enterprise site key, and enterprisePayload when the page passes +one to grecaptcha.enterprise.render(); the returned gRecaptchaResponse still +requires site-specific submission and verification. It uses +RecaptchaV2EnterpriseTaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and extract the Enterprise site key and payload. STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and call solve() without a customer proxy. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 84b3de7..642fec8 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 challenge. +This example solves reCAPTCHA v2 through your own proxy. Supply the page URL, +widget data-sitekey, and proxy connection details; the service returns +gRecaptchaResponse for site-specific submission and verification. It uses +RecaptchaV2Task and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, page parameters, and customer proxy credentials. STEP-02 - Create RecaptchaV2Task and call solve() through that proxy. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index 5956e98..9bac552 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v2 challenge. +This example solves reCAPTCHA v2 without a customer proxy. Supply the target +page URL and the widget's data-sitekey; the service returns +gRecaptchaResponse, which your integration must submit and verify using the +page-specific flow. It uses RecaptchaV2TaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and obtain the page URL and data-sitekey. STEP-02 - Create RecaptchaV2TaskProxyless and call solve() without a customer proxy. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index e5769e0..a8c920a 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -1,6 +1,11 @@ """ Example: Solve a reCAPTCHA v3 challenge. +This example solves score-based reCAPTCHA v3 without a customer proxy. Extract +the site key and page action from grecaptcha.execute(), choose the required +minimum score, and submit the returned gRecaptchaResponse through the target's +own flow. It uses RecaptchaV3TaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). STEP-02 - Create RecaptchaV3TaskProxyless with the required score and call solve(). diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 505ca73..022cc1b 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -1,6 +1,12 @@ """ Example: Solve a Tencent captcha challenge. +This example solves Tencent CAPTCHA through your own proxy. Obtain appId and any +custom captchaScript from the target page, provide the proxy details, and pass +the returned ticket and randstr to the page-specific callback. It uses +TencentTask and CaptchaClient.solve(); callback delivery alone is not proof of +server-side acceptance. + How it works: STEP-01 - Configure CaptchaClient, Tencent parameters, and customer proxy credentials. STEP-02 - Create TencentTask and call solve() through that proxy. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 85b32d4..5824f5b 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Tencent captcha challenge. +This example solves Tencent CAPTCHA without a customer proxy. Obtain appId and +any custom captchaScript from the target page, then deliver the returned ticket +and randstr to its registered callback and verify acceptance separately. It uses +TencentTaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and obtain appId from the target page's Tencent setup. STEP-02 - Create TencentTaskProxyless and call solve() without a customer proxy. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 071310f..f267493 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a Cloudflare Turnstile challenge. +This example solves a Turnstile widget through your own proxy. Supply the page +and widget parameters together with proxy connection details, then apply and +verify the returned token using the target page's own callback or form flow. It +uses TurnstileTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, widget parameters, and customer proxy credentials. STEP-02 - Create TurnstileTask and call solve() through that proxy. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 2b20421..70d04ae 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Cloudflare Turnstile challenge. +This example solves a Turnstile widget without a customer proxy. Supply the +page URL and data-sitekey plus action, data, pagedata, and matching User-Agent +when the page uses them; then apply the returned token through the page-specific +callback or field. It uses TurnstileTaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and extract the widget key and optional challenge data. STEP-02 - Create TurnstileTaskProxyless and call solve() without a customer proxy. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 7a9cb97..6492e84 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -1,5 +1,10 @@ """Example: Solve an image-based Yandex SmartCaptcha. +This example reads a local Yandex SmartCaptcha image and its instruction image, +encodes both as Base64, sends them directly without a proxy, and prints the +ordered click coordinates. It uses YandexSmartCaptchaImageTask and +CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and locate the bundled challenge images. STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 6b37dc6..d0f92c3 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -1,6 +1,11 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). +This example solves token-based Yandex SmartCaptcha through your own proxy. +Supply the page URL, sitekey, and proxy details; then submit and verify the +returned token through the target's site-specific flow. It uses +YandexSmartCaptchaTask and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. STEP-02 - Create YandexSmartCaptchaTask and call solve() through that proxy. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index bc6f67f..72e3c42 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -1,6 +1,11 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). +This example solves token-based Yandex SmartCaptcha without a customer proxy. +Supply the target page URL and sitekey from its widget or iframe; the returned +token must be submitted through the page's smart-token or backend flow and then +verified there. It uses YandexSmartCaptchaTaskProxyless and CaptchaClient.solve(). + How it works: STEP-01 - Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. STEP-02 - Create YandexSmartCaptchaTaskProxyless and call solve() without a customer proxy. From 6deb0876d16be62afb99d671952e2ec23acab0aa Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 17:59:16 +0300 Subject: [PATCH 07/18] docs: clarify API key placeholders --- examples/async/balance.py | 6 +++--- examples/sync/balance.py | 6 +++--- examples/sync/coordinates.py | 6 +++--- examples/sync/geetest_v3_proxy.py | 6 +++--- examples/sync/geetest_v3_proxyless.py | 6 +++--- examples/sync/geetest_v4_proxy.py | 6 +++--- examples/sync/geetest_v4_proxyless.py | 6 +++--- examples/sync/image_to_text.py | 6 +++--- examples/sync/recaptcha_v2_enterprise_proxy.py | 6 +++--- examples/sync/recaptcha_v2_enterprise_proxyless.py | 6 +++--- examples/sync/recaptcha_v2_proxy.py | 6 +++--- examples/sync/recaptcha_v2_proxyless.py | 6 +++--- examples/sync/recaptcha_v3.py | 6 +++--- examples/sync/turnstile_proxy.py | 6 +++--- examples/sync/turnstile_proxyless.py | 6 +++--- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/examples/async/balance.py b/examples/async/balance.py index 1b67280..63d220e 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -34,10 +34,10 @@ from captcha_solver_api import AsyncCaptchaClient # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure the API key and create AsyncCaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/balance.py b/examples/sync/balance.py index 85c26a3..515578f 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -33,10 +33,10 @@ from captcha_solver_api import CaptchaClient # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure the API key and create CaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index 412a878..bd2eb4e 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -40,10 +40,10 @@ from captcha_solver_api.tasks import CoordinatesTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index 9d9b116..5de2eb5 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -44,10 +44,10 @@ from captcha_solver_api.tasks import GeeTestTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index bbbfed4..2b6d263 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -44,10 +44,10 @@ from captcha_solver_api.tasks import GeeTestTaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index edbbd96..40855a2 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -39,10 +39,10 @@ from captcha_solver_api.tasks import GeeTestTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index b04c893..1991eb6 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -39,10 +39,10 @@ from captcha_solver_api.tasks import GeeTestTaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 3af5ccc..2097b3b 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -38,10 +38,10 @@ from captcha_solver_api.tasks import ImageToTextTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index dcf978e..a220d2f 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -37,10 +37,10 @@ from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index e3a67ae..ed037fd 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -38,10 +38,10 @@ from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 642fec8..590df4c 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -36,10 +36,10 @@ from captcha_solver_api.tasks import RecaptchaV2Task # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index 9bac552..b93d851 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -36,10 +36,10 @@ from captcha_solver_api.tasks import RecaptchaV2TaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index a8c920a..1c640a5 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -38,10 +38,10 @@ from captcha_solver_api.tasks import RecaptchaV3TaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index f267493..bb19406 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -37,10 +37,10 @@ from captcha_solver_api.tasks import TurnstileTask # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 70d04ae..f34ba88 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -37,10 +37,10 @@ from captcha_solver_api.tasks import TurnstileTaskProxyless # in this example we store the API key inside environment variables that can be set like: -# export CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS -# set CAPTCHA_API_KEY=1abc234de56fab7c89012d34e56fa7b8 on Windows +# export CAPTCHA_API_KEY=your_api_key on Linux or macOS +# set CAPTCHA_API_KEY=your_api_key on Windows # you can just set the API key directly to its value like: -# api_key="1abc234de56fab7c89012d34e56fa7b8" +# api_key="your_api_key" # STEP-01: Configure CaptchaClient and extract the widget key and optional challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") From 4cdc8787aad7d6d12c206f36f800115efa331119 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 18:11:59 +0300 Subject: [PATCH 08/18] fix: align debug output with JavaScript SDK --- captcha_solver_api/_debug.py | 31 +++++++++++---------- captcha_solver_api/async_client.py | 17 ++++++++---- captcha_solver_api/client.py | 17 ++++++++---- tests/async/test_async_debug.py | 28 +++++++++++++++++-- tests/sync/test_debug.py | 44 +++++++++++++++++++++++------- 5 files changed, 98 insertions(+), 39 deletions(-) diff --git a/captcha_solver_api/_debug.py b/captcha_solver_api/_debug.py index 3088d7f..c86d8ff 100644 --- a/captcha_solver_api/_debug.py +++ b/captcha_solver_api/_debug.py @@ -33,7 +33,7 @@ def _sanitize(value: Any, key: str = "") -> Any: if isinstance(value, (list, tuple)): return [_sanitize(item) for item in value] if isinstance(value, str) and len(value) > 200: - return f"{value[:40]}...{value[-40:]} [truncated, {len(value)} chars]" + return f"{value[:40]}...[{len(value)} chars]...{value[-40:]}" return value @@ -55,7 +55,9 @@ def _error_details(error: BaseException) -> str: while current is not None and len(details) < 4 and id(current) not in seen: seen.add(id(current)) text = str(current).replace("\n", " ").strip() - details.append(f"{type(current).__name__}: {text}" if text else type(current).__name__) + description = f"{type(current).__name__}: {text}" if text else type(current).__name__ + if not (details and text and str(error) == text): + details.append(description) current = current.__cause__ or current.__context__ return " <- ".join(details) @@ -90,12 +92,8 @@ def emit(self, message: str) -> None: def initialized(self, version: str, base_url: str, timeout: Any, polling: Any) -> None: self.emit( - "initialized\n" - f" sdkVersion: {version}\n" - f" baseUrl: {base_url}\n" - " httpTimeout: 30s\n" - f" pollingTimeout: {timeout}s\n" - f" pollingInterval: {polling}s" + f"client initialized sdk=python-sdk/{version} baseUrl={base_url} " + f"httpTimeout=30s timeout={timeout}s pollingInterval={polling}s" ) def request_success( @@ -136,6 +134,7 @@ def request_failure( ) -> None: try: context = _request_context(endpoint, payload) + label = f"{endpoint} {context}".rstrip() detail = _error_details(error) if status is None: response = ( @@ -154,7 +153,7 @@ def request_failure( else: response = f"RESPONSE (HTTP {status} {reason}, {elapsed_ms}ms):\n{_json(data)}" self.emit( - f"{endpoint} {context} -> failed: {detail} ({elapsed_ms}ms)\n" + f"{label} -> failed: {detail} ({elapsed_ms}ms)\n" f"REQUEST (POST {url}):\n{_json(payload)}\n{response}" ) except Exception: @@ -171,7 +170,7 @@ def solve_summary( error: Optional[BaseException] = None, ) -> None: try: - server_time = "-" + server_time: Optional[str] = None if result is not None: created = result.get("createTime") ended = result.get("endTime") @@ -181,11 +180,13 @@ def solve_summary( "SOLVE SUMMARY:", f" status: {'solved' if solved else 'not solved'}", f" taskId: {task_id if task_id is not None else '- (task was not created)'}", - f" taskType: {task_type or '-'}", - f" elapsed: {elapsed:.3f}s", - f" serverSolveTime: {server_time}", - f" polls: {polls}", ] + if task_type: + lines.append(f" taskType: {task_type}") + lines.append(f" elapsed: {elapsed:.3f}s") + if server_time is not None: + lines.append(f" serverSolveTime: {server_time}") + lines.append(f" polls: {polls}") if error is not None: lines.append(f" error: {_error_details(error)}") self.emit("\n".join(lines)) @@ -208,7 +209,7 @@ def _summary(endpoint: str, payload: Dict[str, Any], data: Dict[str, Any]) -> st if data.get("errorId", 0) != 0: code = data.get("errorCode", "UNKNOWN_ERROR") message = data.get("errorDescription", "Unknown API error.") - return f"{prefix} -> failed: ApiError [{code}] {message}" + return f"{prefix} -> failed: ApiError {code}: {message}" if endpoint == "createTask": return f"{prefix} -> taskId={data.get('taskId')}" if endpoint == "getTaskResult": diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index 3d47d0c..4d6c8be 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -143,19 +143,22 @@ async def _request( response.raise_for_status() except httpx.TimeoutException as exc: error_response = getattr(exc, "response", None) + timeout_failure = CaptchaTimeoutError("Request timed out.") self._debug.request_failure( endpoint, url, payload, - exc, + timeout_failure, round((time.monotonic() - started) * 1000), status=getattr(error_response, "status_code", None), reason=getattr(error_response, "reason_phrase", "") or "", body_missing=error_response is not None, ) - raise CaptchaTimeoutError("Request timed out.") from exc + raise timeout_failure from exc except httpx.HTTPError as exc: error_response = getattr(exc, "response", None) + network_failure = NetworkError(str(exc)) + network_failure.__cause__ = exc data = None invalid_json = False if error_response is not None: @@ -167,29 +170,31 @@ async def _request( endpoint, url, payload, - exc, + network_failure, round((time.monotonic() - started) * 1000), status=getattr(error_response, "status_code", None), reason=getattr(error_response, "reason_phrase", "") or "", data=data, invalid_json=invalid_json, ) - raise NetworkError(str(exc)) from exc + raise network_failure from exc try: data = response.json() except ValueError as exc: + parse_failure = NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") + parse_failure.__cause__ = exc self._debug.request_failure( endpoint, url, payload, - exc, + parse_failure, round((time.monotonic() - started) * 1000), status=response.status_code, reason=response.reason_phrase or "", invalid_json=True, ) - raise NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") from exc + raise parse_failure from exc if not isinstance(data, dict): error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") diff --git a/captcha_solver_api/client.py b/captcha_solver_api/client.py index 1e30249..15282b9 100644 --- a/captcha_solver_api/client.py +++ b/captcha_solver_api/client.py @@ -133,19 +133,22 @@ def _request( response.raise_for_status() except requests.exceptions.Timeout as exc: error_response = getattr(exc, "response", None) + timeout_failure = CaptchaTimeoutError("Request timed out.") self._debug.request_failure( endpoint, url, payload, - exc, + timeout_failure, round((time.monotonic() - started) * 1000), status=getattr(error_response, "status_code", None), reason=getattr(error_response, "reason", "") or "", body_missing=error_response is not None, ) - raise CaptchaTimeoutError("Request timed out.") from exc + raise timeout_failure from exc except requests.exceptions.RequestException as exc: error_response = getattr(exc, "response", None) + network_failure = NetworkError(str(exc)) + network_failure.__cause__ = exc data = None invalid_json = False if error_response is not None: @@ -157,29 +160,31 @@ def _request( endpoint, url, payload, - exc, + network_failure, round((time.monotonic() - started) * 1000), status=getattr(error_response, "status_code", None), reason=getattr(error_response, "reason", "") or "", data=data, invalid_json=invalid_json, ) - raise NetworkError(str(exc)) from exc + raise network_failure from exc try: data = response.json() except ValueError as exc: + parse_failure = NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") + parse_failure.__cause__ = exc self._debug.request_failure( endpoint, url, payload, - exc, + parse_failure, round((time.monotonic() - started) * 1000), status=response.status_code, reason=response.reason or "", invalid_json=True, ) - raise NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") from exc + raise parse_failure from exc if not isinstance(data, dict): error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") diff --git a/tests/async/test_async_debug.py b/tests/async/test_async_debug.py index ff42350..405dc1f 100644 --- a/tests/async/test_async_debug.py +++ b/tests/async/test_async_debug.py @@ -56,13 +56,18 @@ async def test_async_debug_transport_timeout_and_isolation(): client._client.post = AsyncMock(side_effect=httpx.ConnectError("dns failed")) with pytest.raises(NetworkError): await client.get_balance() - assert "RESPONSE: none - no response from the server" in messages(client)[0] + assert "failed: NetworkError" in messages(client)[0] + assert "failed: NetworkError: dns failed" in messages(client)[0] + assert "RESPONSE: none - no response from the server (NetworkError" in messages(client)[0] client._debug.logger.debug = Mock() client._client.post = AsyncMock(side_effect=httpx.ReadTimeout("slow")) with pytest.raises(CaptchaTimeoutError): await client.get_balance() - assert "Timeout" in messages(client)[0] + assert "failed: CaptchaTimeoutError: Request timed out." in messages(client)[0] + assert ( + "RESPONSE: none - no response from the server (CaptchaTimeoutError" in messages(client)[0] + ) client._debug.logger.debug = Mock(side_effect=RuntimeError("logger failed")) client._client.post = AsyncMock( @@ -74,6 +79,25 @@ async def test_async_debug_transport_timeout_and_isolation(): await client.aclose() +async def test_async_timeout_after_headers_reports_body_was_not_received(): + client = AsyncCaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + error = httpx.ReadTimeout("body read timed out") + error.response = httpx.Response( + 200, request=httpx.Request("POST", "https://api.captcha-solver.com/getBalance") + ) + client._client.post = AsyncMock(side_effect=error) + + with pytest.raises(CaptchaTimeoutError): + await client.get_balance() + + message = messages(client)[0] + assert "failed: CaptchaTimeoutError: Request timed out." in message + assert "RESPONSE (HTTP 200 OK" in message + assert "body was not received (CaptchaTimeoutError)" in message + await client.aclose() + + async def test_async_failed_solve_has_summary_when_task_not_created(): client = AsyncCaptchaClient("secret", debug=True) client._debug.logger.debug = Mock() diff --git a/tests/sync/test_debug.py b/tests/sync/test_debug.py index 91592cf..15d3beb 100644 --- a/tests/sync/test_debug.py +++ b/tests/sync/test_debug.py @@ -1,3 +1,4 @@ +import re from unittest.mock import Mock, patch import pytest @@ -32,11 +33,15 @@ def test_debug_initialization_is_one_timestamped_event(): logger.assert_called_once() message = logger.call_args.args[0] - assert message.startswith("[") - assert "] [CaptchaClient] initialized" in message - assert "sdkVersion:" in message - assert "baseUrl:" in message - assert "pollingInterval:" in message + assert re.match( + r"^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [+-]\d{2}:\d{2}\] " + r"\[CaptchaClient\] client initialized ", + message, + ) + assert "sdk=python-sdk/" in message + assert "baseUrl=" in message + assert "pollingInterval=" in message + assert "\n" not in message def test_success_masks_and_truncates_without_mutating_payload(): @@ -64,7 +69,7 @@ def test_success_masks_and_truncates_without_mutating_payload(): assert "127.0.0.1" not in message assert "[MASKED]" in message assert "[base64, 300 chars]" in message - assert "[truncated, 250 chars]" in message + assert f"{'x' * 40}...[250 chars]...{'x' * 40}" in message assert payload["clientKey"] == "api-secret" assert payload["task"]["body"] == body @@ -104,9 +109,9 @@ def test_api_and_http_errors_include_paired_request_response(): client.get_balance() api_message, http_message = debug_messages(client) - assert "failed: ApiError [ERROR_KEY_DOES_NOT_EXIST]" in api_message + assert "failed: ApiError ERROR_KEY_DOES_NOT_EXIST: Account not found" in api_message assert "REQUEST" in api_message and "RESPONSE (HTTP 200 OK" in api_message - assert "failed: HTTPError" in http_message + assert "failed: NetworkError" in http_message assert "RESPONSE (HTTP 502 Bad Gateway" in http_message assert "upstream failed" in http_message @@ -129,8 +134,26 @@ def test_invalid_json_network_and_timeout_explain_missing_response(): invalid_message, network_message, timeout_message = debug_messages(client) assert "body is not valid JSON" in invalid_message - assert "RESPONSE: none - no response from the server (ConnectionError" in network_message - assert "RESPONSE: none - no response from the server (Timeout" in timeout_message + assert "RESPONSE: none - no response from the server (NetworkError" in network_message + assert "failed: NetworkError: dns failed" in network_message + assert "RESPONSE: none - no response from the server (CaptchaTimeoutError" in timeout_message + + +def test_timeout_after_headers_reports_body_was_not_received(): + client = CaptchaClient("secret", debug=True) + client._debug.logger.debug = Mock() + partial_response = response(status=200, reason="OK") + client.session.post = Mock( + side_effect=requests.Timeout("body read timed out", response=partial_response) + ) + + with pytest.raises(CaptchaTimeoutError): + client.get_balance() + + message = debug_messages(client)[0] + assert "failed: CaptchaTimeoutError: Request timed out." in message + assert "RESPONSE (HTTP 200 OK" in message + assert "body was not received (CaptchaTimeoutError)" in message def test_solve_summary_reports_success_failure_and_poll_count(): @@ -167,6 +190,7 @@ def test_solve_summary_reports_success_failure_and_poll_count(): assert "status: not solved" in summary assert "taskId: - (task was not created)" in summary assert "error:" in summary + assert "serverSolveTime:" not in summary def test_debug_failure_does_not_change_result_or_exception(): From d51c14c611ec898c1228bbd7c2bdef29e348f183 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 18:21:12 +0300 Subject: [PATCH 09/18] docs: support debug flag in all examples --- README.md | 9 +++++---- examples/_cli.py | 15 +++++++++++++++ examples/async/balance.py | 3 ++- examples/async/coordinates.py | 3 ++- examples/async/geetest_v3_proxy.py | 5 ++++- examples/async/geetest_v3_proxyless.py | 5 ++++- examples/async/geetest_v4_proxy.py | 5 ++++- examples/async/geetest_v4_proxyless.py | 5 ++++- examples/async/image_to_text.py | 3 ++- examples/async/recaptcha_v2_enterprise_proxy.py | 3 ++- .../async/recaptcha_v2_enterprise_proxyless.py | 3 ++- examples/async/recaptcha_v2_proxy.py | 3 ++- examples/async/recaptcha_v2_proxyless.py | 3 ++- examples/async/recaptcha_v3.py | 3 ++- examples/async/tencent_proxy.py | 3 ++- examples/async/tencent_proxyless.py | 3 ++- examples/async/turnstile_proxy.py | 3 ++- examples/async/turnstile_proxyless.py | 3 ++- examples/async/yandex_smartcaptcha_image.py | 3 ++- examples/async/yandex_smartcaptcha_proxy.py | 3 ++- examples/async/yandex_smartcaptcha_proxyless.py | 3 ++- examples/sync/balance.py | 3 ++- examples/sync/coordinates.py | 3 ++- examples/sync/debug_mode.py | 13 +++++++------ examples/sync/geetest_v3_proxy.py | 3 ++- examples/sync/geetest_v3_proxyless.py | 3 ++- examples/sync/geetest_v4_proxy.py | 3 ++- examples/sync/geetest_v4_proxyless.py | 3 ++- examples/sync/image_to_text.py | 3 ++- examples/sync/recaptcha_v2_enterprise_proxy.py | 3 ++- .../sync/recaptcha_v2_enterprise_proxyless.py | 3 ++- examples/sync/recaptcha_v2_proxy.py | 3 ++- examples/sync/recaptcha_v2_proxyless.py | 3 ++- examples/sync/recaptcha_v3.py | 3 ++- examples/sync/tencent_proxy.py | 3 ++- examples/sync/tencent_proxyless.py | 3 ++- examples/sync/turnstile_proxy.py | 3 ++- examples/sync/turnstile_proxyless.py | 3 ++- examples/sync/yandex_smartcaptcha_image.py | 3 ++- examples/sync/yandex_smartcaptcha_proxy.py | 3 ++- examples/sync/yandex_smartcaptcha_proxyless.py | 3 ++- 41 files changed, 111 insertions(+), 48 deletions(-) create mode 100644 examples/_cli.py diff --git a/README.md b/README.md index c7d12d1..f1f7a7d 100644 --- a/README.md +++ b/README.md @@ -705,14 +705,15 @@ their first and last 40 characters plus the original length. The SDK does not lo URLs and custom task fields can still contain application data, so review logs before sharing them publicly. -Run the dedicated example from the repository root: +Every runnable sync and async example accepts the same `--debug` flag. For example: ```bash -python examples/sync/debug_mode.py +python examples/sync/image_to_text.py --debug ``` -It reads `CAPTCHA_API_KEY` from the environment or `.env`, uses the bundled image asset, and -creates a real paid CAPTCHA task. See [`examples/sync/debug_mode.py`](examples/sync/debug_mode.py). +Examples read `CAPTCHA_API_KEY` from the environment or `.env`. They create real paid CAPTCHA +tasks unless their description says otherwise. The dedicated walkthrough remains available at +[`examples/sync/debug_mode.py`](examples/sync/debug_mode.py). ### Custom timeout and polling diff --git a/examples/_cli.py b/examples/_cli.py new file mode 100644 index 0000000..e254273 --- /dev/null +++ b/examples/_cli.py @@ -0,0 +1,15 @@ +"""Shared command-line options for runnable SDK examples.""" + +import argparse +from typing import Optional, Sequence + + +def debug_enabled(argv: Optional[Sequence[str]] = None) -> bool: + """Return whether sanitized SDK debug logging was requested.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--debug", + action="store_true", + help="enable sanitized SDK request, response, timing, and solve-summary logs", + ) + return parser.parse_args(argv).debug diff --git a/examples/async/balance.py b/examples/async/balance.py index 63d220e..f0868a6 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -32,6 +32,7 @@ load_dotenv(os.path.join(repo_root, ".env")) from captcha_solver_api import AsyncCaptchaClient +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -44,7 +45,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. # Get the current account balance. # Returns a float with the available amount in your account currency. diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 54a62bb..32d7ad1 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -39,13 +39,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import CoordinatesTask +from examples._cli import debug_enabled api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index 8ea9804..5d8164c 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -43,6 +43,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -55,7 +56,9 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient( + api_key, debug=debug_enabled(), timeout=300, polling_interval=10 + ) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 2f2ae34..80418eb 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -43,6 +43,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -55,7 +56,9 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient( + api_key, debug=debug_enabled(), timeout=300, polling_interval=10 + ) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index ab8a888..b6e9f9f 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -38,6 +38,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -45,7 +46,9 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient( + api_key, debug=debug_enabled(), timeout=300, polling_interval=10 + ) as solver: # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 8c5d9a6..a6ccef1 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -38,6 +38,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -45,7 +46,9 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient( + api_key, debug=debug_enabled(), timeout=300, polling_interval=10 + ) as solver: # --- Proxyless example --- # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 3b8bbef..876dab8 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -36,6 +36,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import ImageToTextTask +from examples._cli import debug_enabled api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -52,7 +53,7 @@ def encode_image(filename): async def main(): # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. # Image to Text tasks are usually fast. Default timeout is fine. - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: digits_body = encode_image("captcha-digits.png") # --- Basic example --- diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 217e85a..2363d3e 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -36,13 +36,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index d24d547..f9d1741 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -37,13 +37,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. # Enterprise captchas are loaded via the reCAPTCHA Enterprise API. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index b81a2cd..34365c1 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -36,6 +36,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2Task +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -44,7 +45,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. # Use when the target site is geo-restricted or you need session consistency. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index dc1b024..0f664f5 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -35,6 +35,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2TaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -43,7 +44,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. The service uses its own IP addresses. try: diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index edabeee..a89ece5 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -37,6 +37,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV3TaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -44,7 +45,7 @@ async def main(): # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=180) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled(), timeout=180) as solver: # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index 520d391..6504573 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -37,13 +37,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- With proxy example --- # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index f56eb34..2345551 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -36,13 +36,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Proxyless example --- # Solves Tencent captcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index 296cd9e..81ac30d 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -36,13 +36,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 064c069..77b1be3 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -36,13 +36,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and extract the widget key and challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. # The token is tied to the User-Agent. If you pass userAgent, use the same diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index 5ce1972..b43ae5c 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -35,6 +35,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaImageTask +from examples._cli import debug_enabled def encode_image(filename: str) -> str: @@ -47,7 +48,7 @@ def encode_image(filename: str) -> str: async def main() -> None: # STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # STEP-02: Encode both images and create YandexSmartCaptchaImageTask. # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index f824b8a..45f839c 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -35,13 +35,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index 0fd950e..cedb9f0 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -35,13 +35,14 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index 515578f..ae12329 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -31,6 +31,7 @@ load_dotenv(os.path.join(repo_root, ".env")) from captcha_solver_api import CaptchaClient +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -42,7 +43,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. # Get the current account balance. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index bd2eb4e..363ba35 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -38,6 +38,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import CoordinatesTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -49,7 +50,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index 4412fe1..5fb8582 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -1,15 +1,15 @@ -"""Run one Image to Text task with sanitized debug logging enabled. +"""Run one Image to Text task with optional sanitized debug logging. This example reads a bundled image as Base64, enables the SDK's opt-in debug -mode, solves the image task, and prints the recognized text after the sanitized -request/response events and SOLVE SUMMARY. It uses ImageToTextTask and -CaptchaClient.solve(). +mode when run with --debug, solves the image task, and prints the recognized +text after the sanitized request/response events and SOLVE SUMMARY. It uses +ImageToTextTask and CaptchaClient.solve(). This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment or in the repository's .env file before running it. How it works: -STEP-01 - Read the bundled image and create CaptchaClient with debug enabled. +STEP-01 - Read the bundled image and create CaptchaClient with optional debug logging. STEP-02 - Create ImageToTextTask and call solve(). STEP-03 - Inspect the sanitized debug events and SOLVE SUMMARY. STEP-04 - Print the recognized text returned by the service. @@ -33,6 +33,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import ImageToTextTask +from examples._cli import debug_enabled # STEP-01: Read the bundled image and create CaptchaClient with debug enabled. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -41,7 +42,7 @@ with open(image_path, "rb") as image_file: image_body = b64encode(image_file.read()).decode("utf-8") -with CaptchaClient(api_key, debug=True) as client: +with CaptchaClient(api_key, debug=debug_enabled()) as client: # STEP-02: Create ImageToTextTask and call solve(). solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index 5de2eb5..1bb1574 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -42,6 +42,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -54,7 +55,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 2b6d263..8cc48c4 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -42,6 +42,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -54,7 +55,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index 40855a2..6ea22f6 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -37,6 +37,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -49,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) # --- With proxy example --- # Solves GeeTest v4 through your own proxy. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index 1991eb6..b2eefa8 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -37,6 +37,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -49,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) # --- Proxyless example --- # Solves GeeTest v4 without a proxy. diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 2097b3b..2445f18 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -36,6 +36,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import ImageToTextTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -48,7 +49,7 @@ # Create a solver instance with your API key. # Image to Text tasks are usually fast. Default timeout is fine. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Basic example --- # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index a220d2f..575883e 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -35,6 +35,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -46,7 +47,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index ed037fd..e908e46 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -36,6 +36,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -47,7 +48,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 590df4c..cf25ab2 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -34,6 +34,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2Task +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -47,7 +48,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index b93d851..b51ddf6 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -34,6 +34,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2TaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -47,7 +48,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index 1c640a5..d85c8b4 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -36,6 +36,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV3TaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -48,7 +49,7 @@ # Create a solver instance with your API key. # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=180) +solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=180) # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 022cc1b..20c80bb 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -36,11 +36,12 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTask +from examples._cli import debug_enabled # STEP-01: Configure CaptchaClient, Tencent parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- With proxy example --- # Solves Tencent captcha through your own proxy. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 5824f5b..0bb9d78 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -35,11 +35,12 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure CaptchaClient and obtain appId from the target page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Proxyless example --- # Solves Tencent captcha without a proxy. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index bb19406..3f8f148 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -35,6 +35,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TurnstileTask +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -46,7 +47,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index f34ba88..06b3e42 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -35,6 +35,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TurnstileTaskProxyless +from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -46,7 +47,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 6492e84..1ced986 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -34,6 +34,7 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaImageTask +from examples._cli import debug_enabled def encode_image(filename: str) -> str: @@ -45,7 +46,7 @@ def encode_image(filename: str) -> str: # STEP-01: Configure CaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # STEP-02: Encode both images and create YandexSmartCaptchaImageTask. try: diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index d0f92c3..13d376c 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -34,11 +34,12 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask +from examples._cli import debug_enabled # STEP-01: Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index 72e3c42..f73d8c8 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -34,11 +34,12 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless +from examples._cli import debug_enabled # STEP-01: Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=debug_enabled()) # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. From c8ab929fd96a418b0be060b33c39e7e85ace8852 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 18:28:02 +0300 Subject: [PATCH 10/18] docs: align README with SDK behavior --- README.md | 9 +++++---- captcha_solver_api/tasks.py | 3 ++- examples/README.md | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f1f7a7d..b447a1d 100644 --- a/README.md +++ b/README.md @@ -624,7 +624,7 @@ Use this method to identify points that a worker should click in a generic image | `body` | yes | The captcha image, base64-encoded. | | `comment` | no (recommended) | Hint for the worker, e.g. `"click on the green apple"`. | | `imgInstructions` | no | Optional instruction image, base64-encoded. | -| `minClicks` | no | Minimum number of clicks expected (default `1`). | +| `minClicks` | no | Minimum number of clicks expected. When unset, the SDK omits this field and lets the API apply its default. | | `maxClicks` | no | Maximum number of clicks allowed. | **Response:** `coordinates` -- a list of `{"x": int, "y": int}` pixel positions to click, in order. @@ -699,7 +699,8 @@ client = CaptchaClient("your_api_key", debug=True) solution = client.solve(task) ``` -Credential, cookie, and proxy fields are replaced with `[MASKED]`. Base64 image fields are +API credentials, cookies, and proxy credentials are replaced with `[MASKED]`. Proxy type and +port remain visible. Base64 image fields are replaced with their character count, and other strings longer than 200 characters retain only their first and last 40 characters plus the original length. The SDK does not log HTTP headers. URLs and custom task fields can still contain application data, so review logs before sharing @@ -742,8 +743,8 @@ check the same task later; calling `solve()` again creates a new task. While polling, `solve()` retries short network failures and HTTP timeouts of `getTaskResult` on the next poll, so a brief outage does not lose an already -created task. After `poll_retries` (default 3) consecutive failures the error is -raised. API errors are not retried, and `createTask` is never retried because +created task. The SDK tolerates up to `poll_retries` (default 3) consecutive +failures and raises the next one. API errors are not retried, and `createTask` is never retried because that could create and pay for a second task. To change the limit: ```python diff --git a/captcha_solver_api/tasks.py b/captcha_solver_api/tasks.py index 38142d9..bf6549d 100644 --- a/captcha_solver_api/tasks.py +++ b/captcha_solver_api/tasks.py @@ -847,7 +847,8 @@ class CoordinatesTask(BaseTask): comment: Optional. Hint for the worker, e.g. `"click on the green apple"`. Recommended for generic click captchas. imgInstructions: Optional. Optional instruction image, base64-encoded. - minClicks: Optional. Minimum number of clicks expected (default `1`). + minClicks: Optional. Minimum number of clicks expected. When unset, the + field is omitted and the API applies its default. maxClicks: Optional. Maximum number of clicks allowed. Returns (`solution` from `solve()`): diff --git a/examples/README.md b/examples/README.md index aea0c90..bc2e4a5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -82,6 +82,16 @@ python examples/sync/yandex_smartcaptcha_kaleidoscope.py python examples/async/recaptcha_v2_proxyless.py ``` +Every sync and async example accepts `--debug` to enable sanitized SDK request, +response, timing, polling, error, and solve-summary logs: + +```bash +python examples/sync/image_to_text.py --debug +``` + +Run any example with `--help` to see its command-line options. Debug mode is +disabled when `--debug` is omitted. + Async scripts create an `AsyncCaptchaClient` and await the same operations as the synchronous client. For several captchas, see the parallel solving pattern in the main [README](../README.md#solving-multiple-captchas-in-parallel). ## Important notes From c52d5d44fd59a86ca4bf18ad02624f88c8a211b8 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Fri, 13 Nov 2026 18:49:51 +0300 Subject: [PATCH 11/18] docs: expand debug constructor guidance --- captcha_solver_api/async_client.py | 15 ++++++++++++--- captcha_solver_api/client.py | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index 4d6c8be..94d9d80 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -43,8 +43,12 @@ class AsyncCaptchaClient: Defaults to 10. Waiting does not block the event loop. language_pool: Default worker pool, e.g. `"en"` or `"ru"`. `None` uses the account default. Can be overridden in `solve()` or `create_task()`. - debug: Emit sanitized request, response, timing, and solve summary logs. - Defaults to `False`. + debug: Enable opt-in diagnostic logging. Logs SDK configuration, + sanitized requests and responses, request timing, polling updates, + errors, and a summary after every `solve()` call. API keys, cookies, + proxy credentials, and Base64 image data are masked. Defaults to + `False`; it is never enabled from an environment variable, and a + logging failure does not change SDK results or exceptions. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -92,7 +96,12 @@ def __init__( applied to every `create_task()`/`solve()` call that doesn't pass its own `language_pool`. Leave unset to use the account's default pool. - debug: Enable sanitized diagnostic logging. Defaults to `False`. + debug: Enable opt-in diagnostic logging. Logs SDK configuration, + sanitized requests and responses, request timing, polling updates, + errors, and a summary after every `solve()` call. API keys, + cookies, proxy credentials, and Base64 image data are masked. + Defaults to `False`; it is never enabled from an environment + variable, and a logging failure does not affect SDK behavior. Raises: ValidationError: `client_key` is missing, empty, or whitespace. diff --git a/captcha_solver_api/client.py b/captcha_solver_api/client.py index 15282b9..5ecf98e 100644 --- a/captcha_solver_api/client.py +++ b/captcha_solver_api/client.py @@ -33,8 +33,12 @@ class CaptchaClient: Defaults to 10. language_pool: Default worker pool, e.g. `"en"` or `"ru"`. `None` uses the account default. Can be overridden in `solve()` or `create_task()`. - debug: Emit sanitized request, response, timing, and solve summary logs. - Defaults to `False`. + debug: Enable opt-in diagnostic logging. Logs SDK configuration, + sanitized requests and responses, request timing, polling updates, + errors, and a summary after every `solve()` call. API keys, cookies, + proxy credentials, and Base64 image data are masked. Defaults to + `False`; it is never enabled from an environment variable, and a + logging failure does not change SDK results or exceptions. Raises: ValidationError: `client_key` is missing, empty, or whitespace. @@ -82,7 +86,12 @@ def __init__( applied to every `create_task()`/`solve()` call that doesn't pass its own `language_pool`. Leave unset to use the account's default pool. - debug: Enable sanitized diagnostic logging. Defaults to `False`. + debug: Enable opt-in diagnostic logging. Logs SDK configuration, + sanitized requests and responses, request timing, polling updates, + errors, and a summary after every `solve()` call. API keys, + cookies, proxy credentials, and Base64 image data are masked. + Defaults to `False`; it is never enabled from an environment + variable, and a logging failure does not affect SDK behavior. Raises: ValidationError: `client_key` is missing, empty, or whitespace. From b81a70f945c37a5f44263b211633db934cf9fbc6 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 15:51:48 +0300 Subject: [PATCH 12/18] fix: address debug mode review feedback --- README.md | 10 ++-- captcha_solver_api/_constants.py | 3 + captcha_solver_api/_debug.py | 32 +++++++++-- captcha_solver_api/async_client.py | 29 +++++++--- captcha_solver_api/client.py | 27 ++++++--- examples/README.md | 10 ++-- examples/_cli.py | 15 ----- examples/async/balance.py | 15 +---- examples/async/coordinates.py | 18 +----- examples/async/debug_mode.py | 43 ++++++++++++++ examples/async/geetest_v3_proxy.py | 20 +------ examples/async/geetest_v3_proxyless.py | 20 +------ examples/async/geetest_v4_proxy.py | 20 +------ examples/async/geetest_v4_proxyless.py | 20 +------ examples/async/image_to_text.py | 17 +----- .../async/recaptcha_v2_enterprise_proxy.py | 18 +----- .../recaptcha_v2_enterprise_proxyless.py | 19 +------ examples/async/recaptcha_v2_proxy.py | 18 +----- examples/async/recaptcha_v2_proxyless.py | 18 +----- examples/async/recaptcha_v3.py | 18 +----- examples/async/tencent_proxy.py | 19 +------ examples/async/tencent_proxyless.py | 18 +----- examples/async/turnstile_proxy.py | 18 +----- examples/async/turnstile_proxyless.py | 18 +----- examples/async/yandex_smartcaptcha_image.py | 18 +----- examples/async/yandex_smartcaptcha_proxy.py | 18 +----- .../async/yandex_smartcaptcha_proxyless.py | 18 +----- examples/sync/balance.py | 15 +---- examples/sync/coordinates.py | 18 +----- examples/sync/debug_mode.py | 9 ++- examples/sync/geetest_v3_proxy.py | 18 +----- examples/sync/geetest_v3_proxyless.py | 18 +----- examples/sync/geetest_v4_proxy.py | 18 +----- examples/sync/geetest_v4_proxyless.py | 18 +----- examples/sync/image_to_text.py | 17 +----- .../sync/recaptcha_v2_enterprise_proxy.py | 18 +----- .../sync/recaptcha_v2_enterprise_proxyless.py | 19 +------ examples/sync/recaptcha_v2_proxy.py | 18 +----- examples/sync/recaptcha_v2_proxyless.py | 18 +----- examples/sync/recaptcha_v3.py | 18 +----- examples/sync/tencent_proxy.py | 19 +------ examples/sync/tencent_proxyless.py | 18 +----- examples/sync/turnstile_proxy.py | 18 +----- examples/sync/turnstile_proxyless.py | 18 +----- examples/sync/yandex_smartcaptcha_image.py | 18 +----- examples/sync/yandex_smartcaptcha_proxy.py | 18 +----- .../sync/yandex_smartcaptcha_proxyless.py | 18 +----- tests/async/test_async_debug.py | 14 ++--- tests/sync/test_debug.py | 56 +++++++++++++++---- 49 files changed, 214 insertions(+), 722 deletions(-) create mode 100644 captcha_solver_api/_constants.py delete mode 100644 examples/_cli.py create mode 100644 examples/async/debug_mode.py diff --git a/README.md b/README.md index b447a1d..7e3b3dd 100644 --- a/README.md +++ b/README.md @@ -706,15 +706,17 @@ their first and last 40 characters plus the original length. The SDK does not lo URLs and custom task fields can still contain application data, so review logs before sharing them publicly. -Every runnable sync and async example accepts the same `--debug` flag. For example: +Dedicated synchronous and asynchronous examples demonstrate debug mode: ```bash -python examples/sync/image_to_text.py --debug +python examples/sync/debug_mode.py +python examples/async/debug_mode.py ``` Examples read `CAPTCHA_API_KEY` from the environment or `.env`. They create real paid CAPTCHA -tasks unless their description says otherwise. The dedicated walkthrough remains available at -[`examples/sync/debug_mode.py`](examples/sync/debug_mode.py). +tasks unless their description says otherwise. See +[`examples/sync/debug_mode.py`](examples/sync/debug_mode.py) and +[`examples/async/debug_mode.py`](examples/async/debug_mode.py). ### Custom timeout and polling diff --git a/captcha_solver_api/_constants.py b/captcha_solver_api/_constants.py new file mode 100644 index 0000000..23fa4e8 --- /dev/null +++ b/captcha_solver_api/_constants.py @@ -0,0 +1,3 @@ +"""Internal constants shared by the synchronous and asynchronous clients.""" + +HTTP_TIMEOUT_SECONDS = 30 diff --git a/captcha_solver_api/_debug.py b/captcha_solver_api/_debug.py index c86d8ff..d5f12aa 100644 --- a/captcha_solver_api/_debug.py +++ b/captcha_solver_api/_debug.py @@ -74,26 +74,46 @@ def __init__(self, enabled: bool, name: str) -> None: def _ensure_default_handler(self) -> None: global _handler + if logging.getLogger().hasHandlers(): + return if _handler is None: _handler = logging.StreamHandler() _handler.setFormatter(logging.Formatter("%(message)s")) if _handler not in self.logger.handlers: self.logger.addHandler(_handler) - self.logger.setLevel(logging.DEBUG) - self.logger.propagate = False def emit(self, message: str) -> None: - if not self.enabled: + if not self.enabled and not self.logger.isEnabledFor(logging.DEBUG): return try: - self.logger.debug(f"[{_timestamp()}] [{self.name}] {message}") + formatted = f"[{_timestamp()}] [{self.name}] {message}" + if self.enabled: + record = self.logger.makeRecord( + self.logger.name, + logging.DEBUG, + "", + 0, + formatted, + (), + None, + ) + self.logger.handle(record) + else: + self.logger.debug(formatted) except Exception: return - def initialized(self, version: str, base_url: str, timeout: Any, polling: Any) -> None: + def initialized( + self, + version: str, + base_url: str, + http_timeout: Any, + timeout: Any, + polling: Any, + ) -> None: self.emit( f"client initialized sdk=python-sdk/{version} baseUrl={base_url} " - f"httpTimeout=30s timeout={timeout}s pollingInterval={polling}s" + f"httpTimeout={http_timeout}s timeout={timeout}s pollingInterval={polling}s" ) def request_success( diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index 94d9d80..12e8049 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -12,6 +12,7 @@ import httpx +from ._constants import HTTP_TIMEOUT_SECONDS from ._debug import DebugLogger from ._version import __version__ from .exceptions import ( @@ -115,7 +116,7 @@ def __init__( self.polling_interval = polling_interval self.language_pool = language_pool self.debug = debug - self._debug = DebugLogger(debug, "AsyncCaptchaClient") + self._debug_log = DebugLogger(debug, "AsyncCaptchaClient") self._client = httpx.AsyncClient( follow_redirects=True, @@ -125,7 +126,13 @@ def __init__( "X-SDK": f"python-sdk/{__version__}", }, ) - self._debug.initialized(__version__, self.base_url, self.timeout, self.polling_interval) + self._debug_log.initialized( + __version__, + self.base_url, + HTTP_TIMEOUT_SECONDS, + self.timeout, + self.polling_interval, + ) async def aclose(self) -> None: """Closes the underlying connection pool. Call this when you're done with @@ -148,12 +155,14 @@ async def _request( started = time.monotonic() try: - response = await self._client.post(url, json=payload, timeout=30) + response = await self._client.post( + url, json=payload, timeout=HTTP_TIMEOUT_SECONDS + ) response.raise_for_status() except httpx.TimeoutException as exc: error_response = getattr(exc, "response", None) timeout_failure = CaptchaTimeoutError("Request timed out.") - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -167,6 +176,7 @@ async def _request( except httpx.HTTPError as exc: error_response = getattr(exc, "response", None) network_failure = NetworkError(str(exc)) + # The debug event is emitted before ``raise ... from exc`` attaches the cause. network_failure.__cause__ = exc data = None invalid_json = False @@ -175,7 +185,7 @@ async def _request( data = error_response.json() except ValueError: invalid_json = True - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -192,8 +202,9 @@ async def _request( data = response.json() except ValueError as exc: parse_failure = NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") + # The debug event is emitted before ``raise ... from exc`` attaches the cause. parse_failure.__cause__ = exc - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -207,7 +218,7 @@ async def _request( if not isinstance(data, dict): error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -218,7 +229,7 @@ async def _request( data=data, ) raise error - self._debug.request_success( + self._debug_log.request_success( endpoint, url, payload, @@ -439,7 +450,7 @@ async def solve( error = exc raise finally: - self._debug.solve_summary( + self._debug_log.solve_summary( solved, task_id, task_type, diff --git a/captcha_solver_api/client.py b/captcha_solver_api/client.py index 5ecf98e..d03e970 100644 --- a/captcha_solver_api/client.py +++ b/captcha_solver_api/client.py @@ -9,6 +9,7 @@ import requests +from ._constants import HTTP_TIMEOUT_SECONDS from ._debug import DebugLogger from ._version import __version__ from .exceptions import ( @@ -105,7 +106,7 @@ def __init__( self.polling_interval = polling_interval self.language_pool = language_pool self.debug = debug - self._debug = DebugLogger(debug, "CaptchaClient") + self._debug_log = DebugLogger(debug, "CaptchaClient") self.session = requests.Session() self.session.headers.update( @@ -115,7 +116,13 @@ def __init__( "X-SDK": f"python-sdk/{__version__}", } ) - self._debug.initialized(__version__, self.base_url, self.timeout, self.polling_interval) + self._debug_log.initialized( + __version__, + self.base_url, + HTTP_TIMEOUT_SECONDS, + self.timeout, + self.polling_interval, + ) def close(self) -> None: """Closes the underlying connection pool. Call this when you're done with @@ -138,12 +145,12 @@ def _request( started = time.monotonic() try: - response = self.session.post(url, json=payload, timeout=30) + response = self.session.post(url, json=payload, timeout=HTTP_TIMEOUT_SECONDS) response.raise_for_status() except requests.exceptions.Timeout as exc: error_response = getattr(exc, "response", None) timeout_failure = CaptchaTimeoutError("Request timed out.") - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -157,6 +164,7 @@ def _request( except requests.exceptions.RequestException as exc: error_response = getattr(exc, "response", None) network_failure = NetworkError(str(exc)) + # The debug event is emitted before ``raise ... from exc`` attaches the cause. network_failure.__cause__ = exc data = None invalid_json = False @@ -165,7 +173,7 @@ def _request( data = error_response.json() except ValueError: invalid_json = True - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -182,8 +190,9 @@ def _request( data = response.json() except ValueError as exc: parse_failure = NetworkError(f"Non-JSON response from API: {response.text[:200]!r}") + # The debug event is emitted before ``raise ... from exc`` attaches the cause. parse_failure.__cause__ = exc - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -197,7 +206,7 @@ def _request( if not isinstance(data, dict): error = NetworkError(f"Unexpected API response shape: {type(data).__name__}") - self._debug.request_failure( + self._debug_log.request_failure( endpoint, url, payload, @@ -208,7 +217,7 @@ def _request( data=data, ) raise error - self._debug.request_success( + self._debug_log.request_success( endpoint, url, payload, @@ -417,7 +426,7 @@ def solve( error = exc raise finally: - self._debug.solve_summary( + self._debug_log.solve_summary( solved, task_id, task_type, diff --git a/examples/README.md b/examples/README.md index bc2e4a5..7d14fb7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -82,15 +82,15 @@ python examples/sync/yandex_smartcaptcha_kaleidoscope.py python examples/async/recaptcha_v2_proxyless.py ``` -Every sync and async example accepts `--debug` to enable sanitized SDK request, -response, timing, polling, error, and solve-summary logs: +Use the dedicated sync or async example to see sanitized SDK request, response, +timing, polling, error, and solve-summary logs: ```bash -python examples/sync/image_to_text.py --debug +python examples/sync/debug_mode.py +python examples/async/debug_mode.py ``` -Run any example with `--help` to see its command-line options. Debug mode is -disabled when `--debug` is omitted. +Both examples enable debug mode directly with `debug=True`. Async scripts create an `AsyncCaptchaClient` and await the same operations as the synchronous client. For several captchas, see the parallel solving pattern in the main [README](../README.md#solving-multiple-captchas-in-parallel). diff --git a/examples/_cli.py b/examples/_cli.py deleted file mode 100644 index e254273..0000000 --- a/examples/_cli.py +++ /dev/null @@ -1,15 +0,0 @@ -"""Shared command-line options for runnable SDK examples.""" - -import argparse -from typing import Optional, Sequence - - -def debug_enabled(argv: Optional[Sequence[str]] = None) -> bool: - """Return whether sanitized SDK debug logging was requested.""" - parser = argparse.ArgumentParser() - parser.add_argument( - "--debug", - action="store_true", - help="enable sanitized SDK request, response, timing, and solve-summary logs", - ) - return parser.parse_args(argv).debug diff --git a/examples/async/balance.py b/examples/async/balance.py index f0868a6..d1d9d78 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -1,15 +1,6 @@ """ Example: Get account balance with the async client. -This example creates AsyncCaptchaClient, requests the current account balance -without creating a CAPTCHA task, and prints the returned amount. It uses -AsyncCaptchaClient.get_balance(). - -How it works: -STEP-01 - Configure the API key and create AsyncCaptchaClient. -STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. -STEP-03 - Print the returned amount or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Returns the current available balance of your account. @@ -32,7 +23,6 @@ load_dotenv(os.path.join(repo_root, ".env")) from captcha_solver_api import AsyncCaptchaClient -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -40,18 +30,15 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure the API key and create AsyncCaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: - # STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. + async with AsyncCaptchaClient(api_key) as solver: # Get the current account balance. # Returns a float with the available amount in your account currency. try: balance = await solver.get_balance() - # STEP-03: Print the returned amount or report the error. print("Balance: " + str(balance)) except Exception as e: sys.exit(e) diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 32d7ad1..70663b6 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -1,17 +1,6 @@ """ Example: Solve a click-based image captcha using CoordinatesTask with the async client. -This example reads local challenge and instruction images, encodes them as -Base64, describes what the worker should click, and prints the ordered -coordinates returned by the service. No proxy or target page is involved. It -uses CoordinatesTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. -STEP-02 - Read the image data and create CoordinatesTask without a proxy. -STEP-03 - Await solve(), which creates the task and polls for its solution. -STEP-04 - Print the coordinates to click in the same order, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. @@ -39,25 +28,21 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import CoordinatesTask -from examples._cli import debug_enabled api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. try: - # STEP-02: Read the image data and create CoordinatesTask without a proxy. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "fruit-click.png"), "rb") as f: body = b64encode(f.read()).decode("utf-8") - # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( CoordinatesTask( body=body, # Base64-encoded captcha image (required) @@ -66,7 +51,6 @@ async def main(): ) # Solution contains {"coordinates": [{"x": 140, "y": 110}]} # Click on each coordinate in order. Coordinates are pixel positions. - # STEP-04: Print the coordinates to click in the same order, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/async/debug_mode.py b/examples/async/debug_mode.py new file mode 100644 index 0000000..ae2e8af --- /dev/null +++ b/examples/async/debug_mode.py @@ -0,0 +1,43 @@ +"""Run one Image to Text task with sanitized async debug logging enabled. + +This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment +or in the repository's .env file before running it. +""" + +import asyncio +import os +import sys +from base64 import b64encode + +try: + from dotenv import load_dotenv +except ModuleNotFoundError as exc: + if exc.name != "dotenv": + raise + load_dotenv = None + +repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +sys.path.append(repo_root) +if load_dotenv is not None: + load_dotenv(os.path.join(repo_root, ".env")) + +from captcha_solver_api import AsyncCaptchaClient +from captcha_solver_api.tasks import ImageToTextTask + + +async def main() -> None: + api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") + image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") + + with open(image_path, "rb") as image_file: + image_body = b64encode(image_file.read()).decode("utf-8") + + async with AsyncCaptchaClient(api_key, debug=True) as client: + solution = await client.solve( + ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6) + ) + + print(f"Recognized text: {solution['text']}") + + +asyncio.run(main()) diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index 5d8164c..ce6bc1e 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v3 challenge with the async client. -This example solves GeeTest v3 through your own proxy. Obtain gt, fetch a fresh -challenge for every task, and supply the proxy details; the returned challenge, -validate, and seccode fields must be submitted and verified by the target. It -uses GeeTestTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. -STEP-02 - Create GeeTestTask with gt and challenge, then await solve() through the proxy. -STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. @@ -43,9 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -56,9 +43,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient( - api_key, debug=debug_enabled(), timeout=300, polling_interval=10 - ) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. @@ -69,7 +54,6 @@ async def main(): # --- With proxy example --- # Solves GeeTest v3 through your own proxy. try: - # STEP-02: Create GeeTestTask with gt and challenge, then await solve() through the proxy. result = await solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -83,10 +67,8 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 80418eb..1d9ffec 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v3 challenge with the async client. -This example solves GeeTest v3 without a customer proxy. Obtain gt from the -widget and fetch a fresh, session-specific challenge from the target for every -task; the service returns challenge, validate, and seccode for the target's -site-specific callback. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. -STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then await solve(). -STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. @@ -43,9 +32,7 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -56,9 +43,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient( - api_key, debug=debug_enabled(), timeout=300, polling_interval=10 - ) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. @@ -70,7 +55,6 @@ async def main(): # Solves GeeTest v3 without a proxy. # v3 is the default version, so the version field can be omitted. try: - # STEP-02: Create GeeTestTaskProxyless with gt and challenge, then await solve(). result = await solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -82,12 +66,10 @@ async def main(): # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) - # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. # Solution contains {"challenge": "...", "validate": "...", "seccode": "..."} # Pass solution.validate and solution.seccode to the page's GeeTest callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index b6e9f9f..506af84 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v4 challenge with the async client. -This example solves GeeTest v4 through your own proxy. Obtain captcha_id from -the target's v4 loader, pass it in initParameters, and supply the proxy details; -the returned v4 fields require site-specific submission and verification. It -uses GeeTestTask with version 4 and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. -STEP-02 - Create GeeTestTask with version 4 and await solve() through the proxy. -STEP-03 - Print the returned v4 fields and explain their site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. @@ -38,21 +27,16 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, obtain captcha_id, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient( - api_key, debug=debug_enabled(), timeout=300, polling_interval=10 - ) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: - # STEP-02: Create GeeTestTask with version 4 and await solve() through the proxy. result = await solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -68,10 +52,8 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print the returned v4 fields and explain their site-specific application. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index a6ccef1..5668b8d 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v4 challenge with the async client. -This example solves GeeTest v4 without a customer proxy. Obtain captcha_id from -the target's v4 loader and pass it in initParameters; the returned v4 fields -must be applied and verified through the target's own flow. It uses -GeeTestTaskProxyless with version 4 and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. -STEP-02 - Create GeeTestTaskProxyless with version 4 and await solve(). -STEP-03 - Print the returned v4 fields and explain their site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. @@ -38,22 +27,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient( - api_key, debug=debug_enabled(), timeout=300, polling_interval=10 - ) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # --- Proxyless example --- # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. try: - # STEP-02: Create GeeTestTaskProxyless with version 4 and await solve(). result = await solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -65,12 +49,10 @@ async def main(): # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) - # STEP-03: Print the returned v4 fields and explain their site-specific application. # Solution contains {"captcha_id": "...", "lot_number": "...", "pass_token": "...", "gen_time": "...", "captcha_output": "..."} # Pass these values together into the page's GeeTest v4 callback as-is. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 876dab8..db6fb9a 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -1,16 +1,6 @@ """ Example: Solve an image captcha with the async client. -This example reads bundled CAPTCHA images as Base64, adds optional answer-format -hints, sends each image directly to the service without a proxy, and prints the -recognized text. It uses ImageToTextTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and locate the bundled images. -STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. -STEP-03 - Await solve(), which creates the task and polls for its solution. -STEP-04 - Print the recognized text, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. @@ -36,7 +26,6 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import ImageToTextTask -from examples._cli import debug_enabled api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -51,17 +40,14 @@ def encode_image(filename): async def main(): - # STEP-01: Configure AsyncCaptchaClient and locate the bundled images. # Image to Text tasks are usually fast. Default timeout is fine. - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: digits_body = encode_image("captcha-digits.png") # --- Basic example --- # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) # with character set hints. try: - # STEP-02: Read an image as Base64 and create ImageToTextTask with answer hints. - # STEP-03: Await solve(), which creates the task and polls for its solution. result = await solver.solve( ImageToTextTask( body=digits_body, # Base64-encoded image (required) @@ -72,7 +58,6 @@ async def main(): ) # Solution contains {"text": "58204"} # Submit solution.text to the target form field. - # STEP-04: Print the recognized text, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 2363d3e..4389924 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. -This example solves reCAPTCHA v2 Enterprise through your own proxy. Supply the -page URL, Enterprise key and payload, and proxy details; the returned -gRecaptchaResponse must be submitted and verified by the target integration. -It uses RecaptchaV2EnterpriseTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. -STEP-02 - Create RecaptchaV2EnterpriseTask and await solve() through that proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -36,19 +25,16 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: - # STEP-02: Create RecaptchaV2EnterpriseTask and await solve() through that proxy. result = await solver.solve( RecaptchaV2EnterpriseTask( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -66,11 +52,9 @@ async def main(): cookies="foo=bar; baz=1", # Session cookies if needed ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index f9d1741..10d157f 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -1,18 +1,6 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. -This example solves reCAPTCHA v2 Enterprise without a customer proxy. Supply -the page URL, Enterprise site key, and enterprisePayload when the page passes -one to grecaptcha.enterprise.render(); the returned gRecaptchaResponse still -requires site-specific submission and verification. It uses -RecaptchaV2EnterpriseTaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and extract the Enterprise site key and payload. -STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and await solve() without a customer proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -37,21 +25,18 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. # Enterprise captchas are loaded via the reCAPTCHA Enterprise API. # If the site passes extra parameters to grecaptcha.enterprise.render(), # you must pass them as enterprisePayload or the token will be rejected. try: - # STEP-02: Create RecaptchaV2EnterpriseTaskProxyless and await solve() without a customer proxy. result = await solver.solve( RecaptchaV2EnterpriseTaskProxyless( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -64,12 +49,10 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 34365c1..6cd87d9 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 challenge through your own proxy with the async client. -This example solves reCAPTCHA v2 through your own proxy. Supply the page URL, -widget data-sitekey, and proxy connection details; the service returns -gRecaptchaResponse for site-specific submission and verification. It uses -RecaptchaV2Task and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. -STEP-02 - Create RecaptchaV2Task and await solve() through that proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -36,21 +25,18 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2Task -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. # Use when the target site is geo-restricted or you need session consistency. try: - # STEP-02: Create RecaptchaV2Task and await solve() through that proxy. result = await solver.solve( RecaptchaV2Task( websiteURL="https://example.com/login", # Full URL of the page with captcha @@ -63,11 +49,9 @@ async def main(): proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index 0f664f5..01d2626 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 challenge without a proxy with the async client. -This example solves reCAPTCHA v2 without a customer proxy. Supply the target -page URL and the widget's data-sitekey; the service returns -gRecaptchaResponse, which your integration must submit and verify using the -page-specific flow. It uses RecaptchaV2TaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. -STEP-02 - Create RecaptchaV2TaskProxyless and await solve() without a customer proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,20 +24,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV2TaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. The service uses its own IP addresses. try: - # STEP-02: Create RecaptchaV2TaskProxyless and await solve() without a customer proxy. # solve() handles task creation, polling, and returns the solution dict. result = await solver.solve( RecaptchaV2TaskProxyless( @@ -57,12 +43,10 @@ async def main(): isInvisible=False, # Set True for invisible reCAPTCHA ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index a89ece5..d4bb2a7 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v3 challenge with the async client. -This example solves score-based reCAPTCHA v3 without a customer proxy. Extract -the site key and page action from grecaptcha.execute(), choose the required -minimum score, and submit the returned gRecaptchaResponse through the target's -own flow. It uses RecaptchaV3TaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). -STEP-02 - Create RecaptchaV3TaskProxyless with the required score and await solve(). -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, websiteKey, and minScore with values from your target @@ -37,20 +26,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import RecaptchaV3TaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and extract the key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, debug=debug_enabled(), timeout=180) as solver: + async with AsyncCaptchaClient(api_key, timeout=180) as solver: # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). try: - # STEP-02: Create RecaptchaV3TaskProxyless with the required score and await solve(). result = await solver.solve( RecaptchaV3TaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the v3 widget @@ -62,12 +48,10 @@ async def main(): # apiDomain='www.recaptcha.net', # Set if site loads from recaptcha.net ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or grecaptcha callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index 6504573..c92644e 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -1,18 +1,6 @@ """ Example: Solve a Tencent captcha challenge with the async client. -This example solves Tencent CAPTCHA through your own proxy. Obtain appId and any -custom captchaScript from the target page, provide the proxy details, and pass -the returned ticket and randstr to the page-specific callback. It uses -TencentTask and AsyncCaptchaClient.solve(); callback delivery alone is not proof -of server-side acceptance. - -How it works: -STEP-01 - Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. -STEP-02 - Create TencentTask and await solve() through that proxy. -STEP-03 - Print ticket and randstr and explain their site-specific application. -STEP-04 - Report errors; page or server acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. @@ -37,19 +25,16 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, Tencent parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: - # STEP-02: Create TencentTask and await solve() through that proxy. result = await solver.solve( TencentTask( websiteURL="https://example.com/register", # Full URL of the page with captcha @@ -63,11 +48,9 @@ async def main(): captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", ) ) - # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains the same appid, ret, ticket, and randstr values. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index 2345551..a840450 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Tencent captcha challenge with the async client. -This example solves Tencent CAPTCHA without a customer proxy. Obtain appId and -any custom captchaScript from the target page, then deliver the returned ticket -and randstr to its registered callback and verify acceptance separately. It uses -TencentTaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. -STEP-02 - Create TencentTaskProxyless and await solve() without a customer proxy. -STEP-03 - Print ticket and randstr and explain their site-specific application. -STEP-04 - Report errors; page or server acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. @@ -36,20 +25,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and obtain appId from the page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Tencent captcha without a proxy. # The service's own proxies are used to solve the captcha. # appId is found in the page source code. captchaScript is optional if the site uses the default. try: - # STEP-02: Create TencentTaskProxyless and await solve() without a customer proxy. result = await solver.solve( TencentTaskProxyless( websiteURL="https://example.com/register", # Full URL of the page using Tencent captcha @@ -58,12 +44,10 @@ async def main(): captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", # Custom script URL if non-default ) ) - # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains {"appid": "...", "ret": 0, "ticket": "...", "randstr": "..."} # Pass all four values together into the page's captcha callback as-is. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index 81ac30d..f46b797 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. -This example solves a Turnstile widget through your own proxy. Supply the page -and widget parameters together with proxy connection details, then apply and -verify the returned token using the target page's own callback or form flow. It -uses TurnstileTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. -STEP-02 - Create TurnstileTask and await solve() through that proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -36,18 +25,15 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: - # STEP-02: Create TurnstileTask and await solve() through that proxy. result = await solver.solve( TurnstileTask( websiteURL="https://example.com/login", # Full URL of the page with Turnstile @@ -65,10 +51,8 @@ async def main(): # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', ) ) - # STEP-03: Print the token and explain its site-specific application. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 77b1be3..76dd7f2 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Cloudflare Turnstile challenge with the async client. -This example solves a Turnstile widget without a customer proxy. Supply the -page URL and data-sitekey plus action, data, pagedata, and matching User-Agent -when the page uses them; then apply the returned token through the page-specific -callback or field. It uses TurnstileTaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and extract the widget key and challenge data. -STEP-02 - Create TurnstileTaskProxyless and await solve() without a customer proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -36,20 +25,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import TurnstileTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and extract the widget key and challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. # The token is tied to the User-Agent. If you pass userAgent, use the same # User-Agent in your browser or bot when submitting the token. try: - # STEP-02: Create TurnstileTaskProxyless and await solve() without a customer proxy. result = await solver.solve( TurnstileTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with a Turnstile widget @@ -61,12 +47,10 @@ async def main(): # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', # Must match the browser submitting the token ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "0.zxcv..."} # Pass this token to the widget callback or cf-turnstile-response field. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index b43ae5c..a89202c 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -1,16 +1,5 @@ """Example: Solve an image-based Yandex SmartCaptcha asynchronously. -This example reads a local Yandex SmartCaptcha image and its instruction image, -encodes both as Base64, sends them directly without a proxy, and prints the -ordered click coordinates. It uses YandexSmartCaptchaImageTask and -AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge images. -STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. -STEP-03 - Await solve(), which creates the task and polls for its solution. -STEP-04 - Print the ordered coordinates to click, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. The sample captcha and instruction images are bundled in examples/assets/. @@ -35,7 +24,6 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaImageTask -from examples._cli import debug_enabled def encode_image(filename: str) -> str: @@ -46,18 +34,14 @@ def encode_image(filename: str) -> str: async def main() -> None: - # STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: - # STEP-02: Encode both images and create YandexSmartCaptchaImageTask. - # STEP-03: Await solve(), which creates the task and polls for its solution. + async with AsyncCaptchaClient(api_key) as solver: result = await solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), imgInstructions=encode_image("yandex-smartcaptcha-instructions.png"), ) ) - # STEP-04: Print the ordered coordinates to click, or report the error. # Click the returned points on the captcha image in the listed order. # Example: {"coordinates": [{"x": 73, "y": 92}, ...]} print("result: " + str(result)) diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 45f839c..5cae19b 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. -This example solves token-based Yandex SmartCaptcha through your own proxy. -Supply the page URL, sitekey, and proxy details; then submit and verify the -returned token through the target's site-specific flow. It uses -YandexSmartCaptchaTask and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. -STEP-02 - Create YandexSmartCaptchaTask and await solve() through that proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,19 +24,16 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient, SmartCaptcha parameters, and proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. try: - # STEP-02: Create YandexSmartCaptchaTask and await solve() through that proxy. result = await solver.solve( YandexSmartCaptchaTask( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -63,11 +49,9 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains the same token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index cedb9f0..9537797 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. -This example solves token-based Yandex SmartCaptcha without a customer proxy. -Supply the target page URL and sitekey from its widget or iframe; the returned -token must be submitted through the page's smart-token or backend flow and then -verified there. It uses YandexSmartCaptchaTaskProxyless and AsyncCaptchaClient.solve(). - -How it works: -STEP-01 - Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. -STEP-02 - Create YandexSmartCaptchaTaskProxyless and await solve() without a customer proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,20 +24,17 @@ from captcha_solver_api import AsyncCaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure AsyncCaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") async def main(): - async with AsyncCaptchaClient(api_key, debug=debug_enabled()) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. # The service's own proxies are used to solve the captcha. # websiteKey is the sitekey value from the page code or captcha iframe. try: - # STEP-02: Create YandexSmartCaptchaTaskProxyless and await solve() without a customer proxy. result = await solver.solve( YandexSmartCaptchaTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -58,12 +44,10 @@ async def main(): # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "dV9xNjYyNTU3NjkxO4k9OTQuNVMuMjkuMjM9..."} # Use solution.token in the smart-token field or pass to your site's backend. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/balance.py b/examples/sync/balance.py index ae12329..5cfa72b 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -1,15 +1,6 @@ """ Example: Get account balance. -This example creates CaptchaClient, requests the current account balance without -creating a CAPTCHA task, and prints the returned amount. It uses -CaptchaClient.get_balance(). - -How it works: -STEP-01 - Configure the API key and create CaptchaClient. -STEP-02 - Request the balance with get_balance() without creating a CAPTCHA task. -STEP-03 - Print the returned amount or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Returns the current available balance of your account. @@ -31,7 +22,6 @@ load_dotenv(os.path.join(repo_root, ".env")) from captcha_solver_api import CaptchaClient -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -39,18 +29,15 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure the API key and create CaptchaClient. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) -# STEP-02: Request the balance with get_balance() without creating a CAPTCHA task. # Get the current account balance. # Returns a float with the available amount in your account currency. try: balance = solver.get_balance() - # STEP-03: Print the returned amount or report the error. print("Balance: " + str(balance)) except Exception as e: sys.exit(e) diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index 363ba35..32a2fd5 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -1,17 +1,6 @@ """ Example: Solve a click-based image captcha using CoordinatesTask. -This example reads local challenge and instruction images, encodes them as -Base64, describes what the worker should click, and prints the ordered -coordinates returned by the service. No proxy or target page is involved. It -uses CoordinatesTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and locate the bundled images. -STEP-02 - Read the image data and create CoordinatesTask without a proxy. -STEP-03 - Call solve(), which creates the task and polls for its solution. -STEP-04 - Print the coordinates to click in the same order, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. @@ -38,7 +27,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import CoordinatesTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -46,23 +34,20 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. try: - # STEP-02: Read the image data and create CoordinatesTask without a proxy. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "fruit-click.png"), "rb") as f: body = b64encode(f.read()).decode("utf-8") - # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( CoordinatesTask( body=body, # Base64-encoded captcha image (required) @@ -71,7 +56,6 @@ ) # Solution contains {"coordinates": [{"x": 140, "y": 110}]} # Click on each coordinate in order. Coordinates are pixel positions. - # STEP-04: Print the coordinates to click in the same order, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py index 5fb8582..4ff70e2 100644 --- a/examples/sync/debug_mode.py +++ b/examples/sync/debug_mode.py @@ -1,7 +1,7 @@ -"""Run one Image to Text task with optional sanitized debug logging. +"""Run one Image to Text task with sanitized debug logging enabled. This example reads a bundled image as Base64, enables the SDK's opt-in debug -mode when run with --debug, solves the image task, and prints the recognized +mode, solves the image task, and prints the recognized text after the sanitized request/response events and SOLVE SUMMARY. It uses ImageToTextTask and CaptchaClient.solve(). @@ -9,7 +9,7 @@ or in the repository's .env file before running it. How it works: -STEP-01 - Read the bundled image and create CaptchaClient with optional debug logging. +STEP-01 - Read the bundled image and create CaptchaClient with debug logging enabled. STEP-02 - Create ImageToTextTask and call solve(). STEP-03 - Inspect the sanitized debug events and SOLVE SUMMARY. STEP-04 - Print the recognized text returned by the service. @@ -33,7 +33,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import ImageToTextTask -from examples._cli import debug_enabled # STEP-01: Read the bundled image and create CaptchaClient with debug enabled. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") @@ -42,7 +41,7 @@ with open(image_path, "rb") as image_file: image_body = b64encode(image_file.read()).decode("utf-8") -with CaptchaClient(api_key, debug=debug_enabled()) as client: +with CaptchaClient(api_key, debug=True) as client: # STEP-02: Create ImageToTextTask and call solve(). solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index 1bb1574..f8a7835 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v3 challenge. -This example solves GeeTest v3 through your own proxy. Obtain gt, fetch a fresh -challenge for every task, and supply the proxy details; the returned challenge, -validate, and seccode fields must be submitted and verified by the target. It -uses GeeTestTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. -STEP-02 - Create GeeTestTask with gt and challenge, then call solve() through the proxy. -STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. @@ -42,7 +31,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -50,12 +38,11 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient, fetch a fresh challenge, and set proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. @@ -71,7 +58,6 @@ # --- With proxy example --- # Solves GeeTest v3 through your own proxy. try: - # STEP-02: Create GeeTestTask with gt and challenge, then call solve() through the proxy. result = solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -85,8 +71,6 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 8cc48c4..9e61e7a 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v3 challenge. -This example solves GeeTest v3 without a customer proxy. Obtain gt from the -widget and fetch a fresh, session-specific challenge from the target for every -task; the service returns challenge, validate, and seccode for the target's -site-specific callback. It uses GeeTestTaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and fetch a fresh v3 challenge from the target. -STEP-02 - Create GeeTestTaskProxyless with gt and challenge, then call solve(). -STEP-03 - Print challenge, validate, and seccode and explain their site-specific use. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. @@ -42,7 +31,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -50,12 +38,11 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and fetch a fresh v3 challenge from the target. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. @@ -72,7 +59,6 @@ # Solves GeeTest v3 without a proxy. # v3 is the default version, so the version field can be omitted. try: - # STEP-02: Create GeeTestTaskProxyless with gt and challenge, then call solve(). result = solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with GeeTest @@ -84,10 +70,8 @@ # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) - # STEP-03: Print challenge, validate, and seccode and explain their site-specific use. # Solution contains {"challenge": "...", "validate": "...", "seccode": "..."} # Pass solution.validate and solution.seccode to the page's GeeTest callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index 6ea22f6..f959cec 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v4 challenge. -This example solves GeeTest v4 through your own proxy. Obtain captcha_id from -the target's v4 loader, pass it in initParameters, and supply the proxy details; -the returned v4 fields require site-specific submission and verification. It -uses GeeTestTask with version 4 and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. -STEP-02 - Create GeeTestTask with version 4 and call solve() through the proxy. -STEP-03 - Print the returned v4 fields and explain their site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. @@ -37,7 +26,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -45,17 +33,15 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient, obtain captcha_id, and set customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: - # STEP-02: Create GeeTestTask with version 4 and call solve() through the proxy. result = solver.solve( GeeTestTask( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -71,8 +57,6 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print the returned v4 fields and explain their site-specific application. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index b2eefa8..f25b5f0 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a GeeTest v4 challenge. -This example solves GeeTest v4 without a customer proxy. Obtain captcha_id from -the target's v4 loader and pass it in initParameters; the returned v4 fields -must be applied and verified through the target's own flow. It uses -GeeTestTaskProxyless with version 4 and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and obtain captcha_id from the target's v4 loader. -STEP-02 - Create GeeTestTaskProxyless with version 4 and call solve(). -STEP-03 - Print the returned v4 fields and explain their site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and captcha_id with values from your target page. @@ -37,7 +26,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import GeeTestTaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -45,18 +33,16 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and obtain captcha_id from the target's v4 loader. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) # --- Proxyless example --- # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. try: - # STEP-02: Create GeeTestTaskProxyless with version 4 and call solve(). result = solver.solve( GeeTestTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the GeeTest widget @@ -68,10 +54,8 @@ # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent ) ) - # STEP-03: Print the returned v4 fields and explain their site-specific application. # Solution contains {"captcha_id": "...", "lot_number": "...", "pass_token": "...", "gen_time": "...", "captcha_output": "..."} # Pass these values together into the page's GeeTest v4 callback as-is. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 2445f18..4a449d7 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -1,16 +1,6 @@ """ Example: Solve an Image to Text challenge. -This example reads bundled CAPTCHA images as Base64, adds optional answer-format -hints, sends each image directly to the service without a proxy, and prints the -recognized text. It uses ImageToTextTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and locate the bundled images. -STEP-02 - Read an image as Base64 and create ImageToTextTask with answer hints. -STEP-03 - Call solve(), which creates the task and polls for its solution. -STEP-04 - Print the recognized text, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Ready to run as-is: sample captcha images are bundled in examples/assets/. @@ -36,7 +26,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import ImageToTextTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -44,24 +33,21 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and locate the bundled images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # Image to Text tasks are usually fast. Default timeout is fine. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Basic example --- # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) # with character set hints. try: - # STEP-02: Read an image as Base64 and create ImageToTextTask with answer hints. # Read and encode the captcha image to base64. # The body must be a pure base64 string without the data:image/...;base64, prefix. with open(os.path.join(assets_dir, "captcha-digits.png"), "rb") as f: digits_body = b64encode(f.read()).decode("utf-8") - # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( ImageToTextTask( body=digits_body, # Base64-encoded image (required) @@ -72,7 +58,6 @@ ) # Solution contains {"text": "58204"} # Submit solution.text to the target form field. - # STEP-04: Print the recognized text, or report the error. print("result: " + str(result)) except Exception as e: sys.exit(e) diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index 575883e..b788161 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. -This example solves reCAPTCHA v2 Enterprise through your own proxy. Supply the -page URL, Enterprise key and payload, and proxy details; the returned -gRecaptchaResponse must be submitted and verified by the target integration. -It uses RecaptchaV2EnterpriseTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. -STEP-02 - Create RecaptchaV2EnterpriseTask and call solve() through that proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,7 +24,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -43,17 +31,15 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient, Enterprise parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: - # STEP-02: Create RecaptchaV2EnterpriseTask and call solve() through that proxy. result = solver.solve( RecaptchaV2EnterpriseTask( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -71,9 +57,7 @@ cookies="foo=bar; baz=1", # Session cookies if needed ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index e908e46..1bb0e1f 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -1,18 +1,6 @@ """ Example: Solve a reCAPTCHA v2 Enterprise challenge. -This example solves reCAPTCHA v2 Enterprise without a customer proxy. Supply -the page URL, Enterprise site key, and enterprisePayload when the page passes -one to grecaptcha.enterprise.render(); the returned gRecaptchaResponse still -requires site-specific submission and verification. It uses -RecaptchaV2EnterpriseTaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and extract the Enterprise site key and payload. -STEP-02 - Create RecaptchaV2EnterpriseTaskProxyless and call solve() without a customer proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -36,7 +24,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2EnterpriseTaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -44,11 +31,10 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and extract the Enterprise site key and payload. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. @@ -56,7 +42,6 @@ # If the site passes extra parameters to grecaptcha.enterprise.render(), # you must pass them as enterprisePayload or the token will be rejected. try: - # STEP-02: Create RecaptchaV2EnterpriseTaskProxyless and call solve() without a customer proxy. result = solver.solve( RecaptchaV2EnterpriseTaskProxyless( websiteURL="https://example.com/login", # Full URL of the Enterprise-protected page @@ -69,10 +54,8 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index cf25ab2..0998e03 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 challenge. -This example solves reCAPTCHA v2 through your own proxy. Supply the page URL, -widget data-sitekey, and proxy connection details; the service returns -gRecaptchaResponse for site-specific submission and verification. It uses -RecaptchaV2Task and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, page parameters, and customer proxy credentials. -STEP-02 - Create RecaptchaV2Task and call solve() through that proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -34,7 +23,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2Task -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -42,19 +30,17 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient, page parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. # Required when the target site is geo-restricted or you need session consistency. try: - # STEP-02: Create RecaptchaV2Task and call solve() through that proxy. result = solver.solve( RecaptchaV2Task( websiteURL="https://example.com/login", # Full URL of the page with captcha @@ -67,9 +53,7 @@ proxyPassword="password", # Password for proxy authorization (optional) ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains the same gRecaptchaResponse token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index b51ddf6..776c62e 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v2 challenge. -This example solves reCAPTCHA v2 without a customer proxy. Supply the target -page URL and the widget's data-sitekey; the service returns -gRecaptchaResponse, which your integration must submit and verify using the -page-specific flow. It uses RecaptchaV2TaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and obtain the page URL and data-sitekey. -STEP-02 - Create RecaptchaV2TaskProxyless and call solve() without a customer proxy. -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -34,7 +23,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV2TaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -42,19 +30,17 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and obtain the page URL and data-sitekey. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. # The service uses its own IP addresses. try: - # STEP-02: Create RecaptchaV2TaskProxyless and call solve() without a customer proxy. # Create a task and wait for the solution. # solve() handles task creation, polling, and returns the solution dict. result = solver.solve( @@ -64,10 +50,8 @@ isInvisible=False, # Set True for invisible reCAPTCHA ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or widget callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index d85c8b4..0ce6775 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -1,17 +1,6 @@ """ Example: Solve a reCAPTCHA v3 challenge. -This example solves score-based reCAPTCHA v3 without a customer proxy. Extract -the site key and page action from grecaptcha.execute(), choose the required -minimum score, and submit the returned gRecaptchaResponse through the target's -own flow. It uses RecaptchaV3TaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). -STEP-02 - Create RecaptchaV3TaskProxyless with the required score and call solve(). -STEP-03 - Print gRecaptchaResponse and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, websiteKey, and minScore with values from your target @@ -36,7 +25,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import RecaptchaV3TaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -44,18 +32,16 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and extract the site key and action from grecaptcha.execute(). api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. -solver = CaptchaClient(api_key, debug=debug_enabled(), timeout=180) +solver = CaptchaClient(api_key, timeout=180) # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). try: - # STEP-02: Create RecaptchaV3TaskProxyless with the required score and call solve(). result = solver.solve( RecaptchaV3TaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with the v3 widget @@ -67,10 +53,8 @@ # apiDomain='www.recaptcha.net', # Set if site loads from recaptcha.net ) ) - # STEP-03: Print gRecaptchaResponse and explain its site-specific application. # Solution contains {"gRecaptchaResponse": "03AGdBq..."} # Pass this token to the g-recaptcha-response field or grecaptcha callback. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 20c80bb..1314907 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -1,18 +1,6 @@ """ Example: Solve a Tencent captcha challenge. -This example solves Tencent CAPTCHA through your own proxy. Obtain appId and any -custom captchaScript from the target page, provide the proxy details, and pass -the returned ticket and randstr to the page-specific callback. It uses -TencentTask and CaptchaClient.solve(); callback delivery alone is not proof of -server-side acceptance. - -How it works: -STEP-01 - Configure CaptchaClient, Tencent parameters, and customer proxy credentials. -STEP-02 - Create TencentTask and call solve() through that proxy. -STEP-03 - Print ticket and randstr and explain their site-specific application. -STEP-04 - Report errors; page or server acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. @@ -36,18 +24,15 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTask -from examples._cli import debug_enabled -# STEP-01: Configure CaptchaClient, Tencent parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. try: - # STEP-02: Create TencentTask and call solve() through that proxy. result = solver.solve( TencentTask( websiteURL="https://example.com/register", # Full URL of the page with captcha @@ -61,9 +46,7 @@ captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", ) ) - # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains the same appid, ret, ticket, and randstr values. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 0bb9d78..fd620bc 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Tencent captcha challenge. -This example solves Tencent CAPTCHA without a customer proxy. Obtain appId and -any custom captchaScript from the target page, then deliver the returned ticket -and randstr to its registered callback and verify acceptance separately. It uses -TencentTaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and obtain appId from the target page's Tencent setup. -STEP-02 - Create TencentTaskProxyless and call solve() without a customer proxy. -STEP-03 - Print ticket and randstr and explain their site-specific application. -STEP-04 - Report errors; page or server acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and appId with values from your target page. @@ -35,19 +24,16 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TencentTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure CaptchaClient and obtain appId from the target page's Tencent setup. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Tencent captcha without a proxy. # The service's own proxies are used to solve the captcha. # appId is found in the page source code. captchaScript is optional if the site uses the default. try: - # STEP-02: Create TencentTaskProxyless and call solve() without a customer proxy. result = solver.solve( TencentTaskProxyless( websiteURL="https://example.com/register", # Full URL of the page using Tencent captcha @@ -56,10 +42,8 @@ captchaScript="https://captchacdn.tencentcloudcs.com/TCaptcha-global.js", # Custom script URL if non-default ) ) - # STEP-03: Print ticket and randstr and explain their site-specific application. # Solution contains {"appid": "...", "ret": 0, "ticket": "...", "randstr": "..."} # Pass all four values together into the page's captcha callback as-is. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page or server acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 3f8f148..748f2e2 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a Cloudflare Turnstile challenge. -This example solves a Turnstile widget through your own proxy. Supply the page -and widget parameters together with proxy connection details, then apply and -verify the returned token using the target page's own callback or form flow. It -uses TurnstileTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, widget parameters, and customer proxy credentials. -STEP-02 - Create TurnstileTask and call solve() through that proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,7 +24,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TurnstileTask -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -43,16 +31,14 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient, widget parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: - # STEP-02: Create TurnstileTask and call solve() through that proxy. result = solver.solve( TurnstileTask( websiteURL="https://example.com/login", # Full URL of the page with Turnstile @@ -70,8 +56,6 @@ # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', ) ) - # STEP-03: Print the token and explain its site-specific application. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 06b3e42..2a32588 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Cloudflare Turnstile challenge. -This example solves a Turnstile widget without a customer proxy. Supply the -page URL and data-sitekey plus action, data, pagedata, and matching User-Agent -when the page uses them; then apply the returned token through the page-specific -callback or field. It uses TurnstileTaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and extract the widget key and optional challenge data. -STEP-02 - Create TurnstileTaskProxyless and call solve() without a customer proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -35,7 +24,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import TurnstileTaskProxyless -from examples._cli import debug_enabled # in this example we store the API key inside environment variables that can be set like: # export CAPTCHA_API_KEY=your_api_key on Linux or macOS @@ -43,18 +31,16 @@ # you can just set the API key directly to its value like: # api_key="your_api_key" -# STEP-01: Configure CaptchaClient and extract the widget key and optional challenge data. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. # The token is tied to the User-Agent. If you pass userAgent, use the same # User-Agent in your browser or bot when submitting the token. try: - # STEP-02: Create TurnstileTaskProxyless and call solve() without a customer proxy. result = solver.solve( TurnstileTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page with a Turnstile widget @@ -66,10 +52,8 @@ # userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...', # Must match the browser submitting the token ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "0.zxcv..."} # Pass this token to the widget callback or cf-turnstile-response field. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 1ced986..9973cdc 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -1,16 +1,5 @@ """Example: Solve an image-based Yandex SmartCaptcha. -This example reads a local Yandex SmartCaptcha image and its instruction image, -encodes both as Base64, sends them directly without a proxy, and prints the -ordered click coordinates. It uses YandexSmartCaptchaImageTask and -CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and locate the bundled challenge images. -STEP-02 - Encode both images and create YandexSmartCaptchaImageTask. -STEP-03 - Call solve(), which creates the task and polls for its solution. -STEP-04 - Print the ordered coordinates to click, or report the error. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. The sample captcha and instruction images are bundled in examples/assets/. @@ -34,7 +23,6 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaImageTask -from examples._cli import debug_enabled def encode_image(filename: str) -> str: @@ -44,20 +32,16 @@ def encode_image(filename: str) -> str: return b64encode(image_file.read()).decode("utf-8") -# STEP-01: Configure CaptchaClient and locate the bundled challenge images. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) -# STEP-02: Encode both images and create YandexSmartCaptchaImageTask. try: - # STEP-03: Call solve(), which creates the task and polls for its solution. result = solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), imgInstructions=encode_image("yandex-smartcaptcha-instructions.png"), ) ) - # STEP-04: Print the ordered coordinates to click, or report the error. # Click the returned points on the captcha image in the listed order. # Example: {"coordinates": [{"x": 73, "y": 92}, ...]} print("result: " + str(result)) diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 13d376c..08a2fc5 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -1,17 +1,6 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). -This example solves token-based Yandex SmartCaptcha through your own proxy. -Supply the page URL, sitekey, and proxy details; then submit and verify the -returned token through the target's site-specific flow. It uses -YandexSmartCaptchaTask and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. -STEP-02 - Create YandexSmartCaptchaTask and call solve() through that proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -34,18 +23,15 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTask -from examples._cli import debug_enabled -# STEP-01: Configure CaptchaClient, SmartCaptcha parameters, and customer proxy credentials. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. try: - # STEP-02: Create YandexSmartCaptchaTask and call solve() through that proxy. result = solver.solve( YandexSmartCaptchaTask( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -61,9 +47,7 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains the same token. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index f73d8c8..af1b089 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -1,17 +1,6 @@ """ Example: Solve a Yandex SmartCaptcha challenge (token-based). -This example solves token-based Yandex SmartCaptcha without a customer proxy. -Supply the target page URL and sitekey from its widget or iframe; the returned -token must be submitted through the page's smart-token or backend flow and then -verified there. It uses YandexSmartCaptchaTaskProxyless and CaptchaClient.solve(). - -How it works: -STEP-01 - Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. -STEP-02 - Create YandexSmartCaptchaTaskProxyless and call solve() without a customer proxy. -STEP-03 - Print the token and explain its site-specific application. -STEP-04 - Report errors; page acceptance must be verified by the integration. - Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL and websiteKey with values from your target page. @@ -34,19 +23,16 @@ from captcha_solver_api import CaptchaClient from captcha_solver_api.tasks import YandexSmartCaptchaTaskProxyless -from examples._cli import debug_enabled -# STEP-01: Configure CaptchaClient and obtain the page URL and SmartCaptcha site key. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=debug_enabled()) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. # The service's own proxies are used to solve the captcha. # websiteKey is the sitekey value from the page code or captcha iframe. try: - # STEP-02: Create YandexSmartCaptchaTaskProxyless and call solve() without a customer proxy. result = solver.solve( YandexSmartCaptchaTaskProxyless( websiteURL="https://example.com/login", # Full URL of the page using SmartCaptcha @@ -56,10 +42,8 @@ # cookies='session=abc123; token=xyz789', # Session cookies if needed ) ) - # STEP-03: Print the token and explain its site-specific application. # Solution contains {"token": "dV9xNjYyNTU3NjkxO4k9OTQuNVMuMjkuMjM9..."} # Use solution.token in the smart-token field or pass to your site's backend. print("result: " + str(result)) except Exception as e: - # STEP-04: Report errors; page acceptance must be verified by the integration. sys.exit(e) diff --git a/tests/async/test_async_debug.py b/tests/async/test_async_debug.py index 405dc1f..5a91792 100644 --- a/tests/async/test_async_debug.py +++ b/tests/async/test_async_debug.py @@ -8,12 +8,12 @@ def messages(client): - return [call.args[0] for call in client._debug.logger.debug.call_args_list] + return [call.args[0].getMessage() for call in client._debug_log.logger.handle.call_args_list] async def test_async_debug_success_processing_summary_and_masking(): client = AsyncCaptchaClient("async-secret", polling_interval=0, debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() task = ImageToTextTask(body="A" * 300) responses = [ httpx.Response( @@ -52,7 +52,7 @@ async def test_async_debug_success_processing_summary_and_masking(): async def test_async_debug_transport_timeout_and_isolation(): client = AsyncCaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() client._client.post = AsyncMock(side_effect=httpx.ConnectError("dns failed")) with pytest.raises(NetworkError): await client.get_balance() @@ -60,7 +60,7 @@ async def test_async_debug_transport_timeout_and_isolation(): assert "failed: NetworkError: dns failed" in messages(client)[0] assert "RESPONSE: none - no response from the server (NetworkError" in messages(client)[0] - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() client._client.post = AsyncMock(side_effect=httpx.ReadTimeout("slow")) with pytest.raises(CaptchaTimeoutError): await client.get_balance() @@ -69,7 +69,7 @@ async def test_async_debug_transport_timeout_and_isolation(): "RESPONSE: none - no response from the server (CaptchaTimeoutError" in messages(client)[0] ) - client._debug.logger.debug = Mock(side_effect=RuntimeError("logger failed")) + client._debug_log.logger.handle = Mock(side_effect=RuntimeError("logger failed")) client._client.post = AsyncMock( return_value=httpx.Response( 200, json={"errorId": 0, "balance": 1.25}, request=httpx.Request("POST", "https://x") @@ -81,7 +81,7 @@ async def test_async_debug_transport_timeout_and_isolation(): async def test_async_timeout_after_headers_reports_body_was_not_received(): client = AsyncCaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() error = httpx.ReadTimeout("body read timed out") error.response = httpx.Response( 200, request=httpx.Request("POST", "https://api.captcha-solver.com/getBalance") @@ -100,7 +100,7 @@ async def test_async_timeout_after_headers_reports_body_was_not_received(): async def test_async_failed_solve_has_summary_when_task_not_created(): client = AsyncCaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() task = ImageToTextTask(body="image") with patch.object(client, "create_task", side_effect=NetworkError("offline")): with pytest.raises(NetworkError): diff --git a/tests/sync/test_debug.py b/tests/sync/test_debug.py index 15d3beb..7f54d05 100644 --- a/tests/sync/test_debug.py +++ b/tests/sync/test_debug.py @@ -1,4 +1,6 @@ +import logging import re +from io import StringIO from unittest.mock import Mock, patch import pytest @@ -18,21 +20,21 @@ def response(status=200, reason="OK", data=None): def debug_messages(client): - return [call.args[0] for call in client._debug.logger.debug.call_args_list] + return [call.args[0].getMessage() for call in client._debug_log.logger.handle.call_args_list] def test_debug_is_disabled_by_default(): client = CaptchaClient("secret") assert client.debug is False - assert client._debug.enabled is False + assert client._debug_log.enabled is False def test_debug_initialization_is_one_timestamped_event(): - with patch("logging.Logger.debug") as logger: + with patch("logging.Logger.handle") as logger: CaptchaClient("secret", debug=True) logger.assert_called_once() - message = logger.call_args.args[0] + message = logger.call_args.args[0].getMessage() assert re.match( r"^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [+-]\d{2}:\d{2}\] " r"\[CaptchaClient\] client initialized ", @@ -44,9 +46,39 @@ def test_debug_initialization_is_one_timestamped_event(): assert "\n" not in message +def test_debug_logs_reach_configured_root_handler(): + stream = StringIO() + handler = logging.StreamHandler(stream) + root_logger = logging.getLogger() + root_logger.addHandler(handler) + try: + CaptchaClient("secret", debug=True) + finally: + root_logger.removeHandler(handler) + + assert "[CaptchaClient] client initialized" in stream.getvalue() + + +def test_standard_logging_can_enable_debug_events_without_flag(): + stream = StringIO() + handler = logging.StreamHandler(stream) + root_logger = logging.getLogger() + sdk_logger = logging.getLogger("captcha_solver_api.CaptchaClient") + previous_level = sdk_logger.level + root_logger.addHandler(handler) + sdk_logger.setLevel(logging.DEBUG) + try: + CaptchaClient("secret") + finally: + sdk_logger.setLevel(previous_level) + root_logger.removeHandler(handler) + + assert "[CaptchaClient] client initialized" in stream.getvalue() + + def test_success_masks_and_truncates_without_mutating_payload(): client = CaptchaClient("api-secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() long_token = "x" * 250 body = "Y" * 300 payload = { @@ -76,7 +108,7 @@ def test_success_masks_and_truncates_without_mutating_payload(): def test_processing_is_compact_single_line(): client = CaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() client.session.post = Mock(return_value=response(data={"errorId": 0, "status": "processing"})) client.get_task_result(42) @@ -89,7 +121,7 @@ def test_processing_is_compact_single_line(): def test_api_and_http_errors_include_paired_request_response(): client = CaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() client.session.post = Mock( side_effect=[ response( @@ -118,7 +150,7 @@ def test_api_and_http_errors_include_paired_request_response(): def test_invalid_json_network_and_timeout_explain_missing_response(): client = CaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() invalid = response() invalid.json.side_effect = ValueError("bad json") client.session.post = Mock( @@ -141,7 +173,7 @@ def test_invalid_json_network_and_timeout_explain_missing_response(): def test_timeout_after_headers_reports_body_was_not_received(): client = CaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() partial_response = response(status=200, reason="OK") client.session.post = Mock( side_effect=requests.Timeout("body read timed out", response=partial_response) @@ -159,7 +191,7 @@ def test_timeout_after_headers_reports_body_was_not_received(): def test_solve_summary_reports_success_failure_and_poll_count(): task = ImageToTextTask(body="image") client = CaptchaClient("secret", polling_interval=0, debug=True) - client._debug.logger.debug = Mock() + client._debug_log.logger.handle = Mock() with patch.object(client, "_request") as request: request.side_effect = [ {"errorId": 0, "taskId": 7}, @@ -182,7 +214,7 @@ def test_solve_summary_reports_success_failure_and_poll_count(): assert "serverSolveTime: 8s" in summary assert "polls: 2" in summary - client._debug.logger.debug.reset_mock() + client._debug_log.logger.handle.reset_mock() with patch.object(client, "create_task", side_effect=ApiError("BAD", "failed")): with pytest.raises(ApiError): client.solve(task) @@ -195,7 +227,7 @@ def test_solve_summary_reports_success_failure_and_poll_count(): def test_debug_failure_does_not_change_result_or_exception(): client = CaptchaClient("secret", debug=True) - client._debug.logger.debug = Mock(side_effect=RuntimeError("logger failed")) + client._debug_log.logger.handle = Mock(side_effect=RuntimeError("logger failed")) client.session.post = Mock(return_value=response(data={"errorId": 0, "balance": 4.5})) assert client.get_balance() == 4.5 From 252a6e124c04cc6ff277e45489b98554119e5cbd Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 15:53:58 +0300 Subject: [PATCH 13/18] test: cover package logger debug configuration --- tests/sync/test_debug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sync/test_debug.py b/tests/sync/test_debug.py index 7f54d05..fa6b863 100644 --- a/tests/sync/test_debug.py +++ b/tests/sync/test_debug.py @@ -63,7 +63,7 @@ def test_standard_logging_can_enable_debug_events_without_flag(): stream = StringIO() handler = logging.StreamHandler(stream) root_logger = logging.getLogger() - sdk_logger = logging.getLogger("captcha_solver_api.CaptchaClient") + sdk_logger = logging.getLogger("captcha_solver_api") previous_level = sdk_logger.level root_logger.addHandler(handler) sdk_logger.setLevel(logging.DEBUG) From 2a369e26b88d3050a0afb36d6542053aab74a122 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 16:12:24 +0300 Subject: [PATCH 14/18] style: format async HTTP request --- captcha_solver_api/async_client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/captcha_solver_api/async_client.py b/captcha_solver_api/async_client.py index 12e8049..92f5c4e 100644 --- a/captcha_solver_api/async_client.py +++ b/captcha_solver_api/async_client.py @@ -155,9 +155,7 @@ async def _request( started = time.monotonic() try: - response = await self._client.post( - url, json=payload, timeout=HTTP_TIMEOUT_SECONDS - ) + response = await self._client.post(url, json=payload, timeout=HTTP_TIMEOUT_SECONDS) response.raise_for_status() except httpx.TimeoutException as exc: error_response = getattr(exc, "response", None) From 9bb580b88a5726223f53a9ef259adc5438a32bf0 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 18:12:08 +0300 Subject: [PATCH 15/18] docs: improve debug examples and usage steps --- README.md | 14 ++--- examples/README.md | 11 +--- examples/async/balance.py | 13 +++-- examples/async/coordinates.py | 14 +++-- examples/async/debug_mode.py | 43 ---------------- examples/async/geetest_v3_proxy.py | 22 +++++--- examples/async/geetest_v3_proxyless.py | 22 +++++--- examples/async/geetest_v4_proxy.py | 14 +++-- examples/async/geetest_v4_proxyless.py | 14 +++-- examples/async/image_to_text.py | 14 +++-- .../async/recaptcha_v2_enterprise_proxy.py | 14 +++-- .../recaptcha_v2_enterprise_proxyless.py | 14 +++-- examples/async/recaptcha_v2_proxy.py | 14 +++-- examples/async/recaptcha_v2_proxyless.py | 14 +++-- examples/async/recaptcha_v3.py | 14 +++-- examples/async/tencent_proxy.py | 14 +++-- examples/async/tencent_proxyless.py | 14 +++-- examples/async/turnstile_proxy.py | 14 +++-- examples/async/turnstile_proxyless.py | 14 +++-- examples/async/yandex_smartcaptcha_image.py | 13 ++++- .../async/yandex_smartcaptcha_kaleidoscope.py | 18 +++---- examples/async/yandex_smartcaptcha_proxy.py | 14 +++-- .../async/yandex_smartcaptcha_proxyless.py | 14 +++-- examples/sync/balance.py | 13 +++-- examples/sync/coordinates.py | 14 +++-- examples/sync/debug_mode.py | 51 ------------------- examples/sync/geetest_v3_proxy.py | 22 +++++--- examples/sync/geetest_v3_proxyless.py | 22 +++++--- examples/sync/geetest_v4_proxy.py | 14 +++-- examples/sync/geetest_v4_proxyless.py | 14 +++-- examples/sync/image_to_text.py | 14 +++-- .../sync/recaptcha_v2_enterprise_proxy.py | 14 +++-- .../sync/recaptcha_v2_enterprise_proxyless.py | 14 +++-- examples/sync/recaptcha_v2_proxy.py | 14 +++-- examples/sync/recaptcha_v2_proxyless.py | 14 +++-- examples/sync/recaptcha_v3.py | 14 +++-- examples/sync/tencent_proxy.py | 14 +++-- examples/sync/tencent_proxyless.py | 14 +++-- examples/sync/turnstile_proxy.py | 14 +++-- examples/sync/turnstile_proxyless.py | 14 +++-- examples/sync/yandex_smartcaptcha_image.py | 13 ++++- .../sync/yandex_smartcaptcha_kaleidoscope.py | 18 +++---- examples/sync/yandex_smartcaptcha_proxy.py | 14 +++-- .../sync/yandex_smartcaptcha_proxyless.py | 14 +++-- 44 files changed, 453 insertions(+), 262 deletions(-) delete mode 100644 examples/async/debug_mode.py delete mode 100644 examples/sync/debug_mode.py diff --git a/README.md b/README.md index 7e3b3dd..7060349 100644 --- a/README.md +++ b/README.md @@ -706,17 +706,9 @@ their first and last 40 characters plus the original length. The SDK does not lo URLs and custom task fields can still contain application data, so review logs before sharing them publicly. -Dedicated synchronous and asynchronous examples demonstrate debug mode: - -```bash -python examples/sync/debug_mode.py -python examples/async/debug_mode.py -``` - -Examples read `CAPTCHA_API_KEY` from the environment or `.env`. They create real paid CAPTCHA -tasks unless their description says otherwise. See -[`examples/sync/debug_mode.py`](examples/sync/debug_mode.py) and -[`examples/async/debug_mode.py`](examples/async/debug_mode.py). +All synchronous and asynchronous examples enable debug mode. They read +`CAPTCHA_API_KEY` from the environment or `.env` and create real paid CAPTCHA +tasks unless their description says otherwise. ### Custom timeout and polling diff --git a/examples/README.md b/examples/README.md index 7d14fb7..b09e5f8 100644 --- a/examples/README.md +++ b/examples/README.md @@ -82,15 +82,8 @@ python examples/sync/yandex_smartcaptcha_kaleidoscope.py python examples/async/recaptcha_v2_proxyless.py ``` -Use the dedicated sync or async example to see sanitized SDK request, response, -timing, polling, error, and solve-summary logs: - -```bash -python examples/sync/debug_mode.py -python examples/async/debug_mode.py -``` - -Both examples enable debug mode directly with `debug=True`. +Every example enables `debug=True`, so running any sync or async script shows +sanitized SDK request, response, timing, polling, error, and solve-summary logs. Async scripts create an `AsyncCaptchaClient` and await the same operations as the synchronous client. For several captchas, see the parallel solving pattern in the main [README](../README.md#solving-multiple-captchas-in-parallel). diff --git a/examples/async/balance.py b/examples/async/balance.py index d1d9d78..cf77ed6 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -1,5 +1,12 @@ -""" -Example: Get account balance with the async client. +"""Example: Check the current captcha solver account balance without creating a captcha task. + +What it does: + This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses AsyncCaptchaClient.get_balance() and returns the account balance. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Call await solver.get_balance(); this does not create or poll a CAPTCHA task. + STEP-03 - Print the balance returned by the API. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -34,7 +41,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # Get the current account balance. # Returns a float with the available amount in your account currency. try: diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 70663b6..14c819d 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -1,5 +1,13 @@ -""" -Example: Solve a click-based image captcha using CoordinatesTask with the async client. +"""Example: Solve click-based image captchas from bundled local images without a proxy. + +What it does: + This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. + STEP-03 - Create CoordinatesTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -33,7 +41,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. diff --git a/examples/async/debug_mode.py b/examples/async/debug_mode.py deleted file mode 100644 index ae2e8af..0000000 --- a/examples/async/debug_mode.py +++ /dev/null @@ -1,43 +0,0 @@ -"""Run one Image to Text task with sanitized async debug logging enabled. - -This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment -or in the repository's .env file before running it. -""" - -import asyncio -import os -import sys -from base64 import b64encode - -try: - from dotenv import load_dotenv -except ModuleNotFoundError as exc: - if exc.name != "dotenv": - raise - load_dotenv = None - -repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) -sys.path.append(repo_root) -if load_dotenv is not None: - load_dotenv(os.path.join(repo_root, ".env")) - -from captcha_solver_api import AsyncCaptchaClient -from captcha_solver_api.tasks import ImageToTextTask - - -async def main() -> None: - api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") - - with open(image_path, "rb") as image_file: - image_body = b64encode(image_file.read()).decode("utf-8") - - async with AsyncCaptchaClient(api_key, debug=True) as client: - solution = await client.solve( - ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6) - ) - - print(f"Recognized text: {solution['text']}") - - -asyncio.run(main()) diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index ce6bc1e..32215da 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -1,15 +1,23 @@ -""" -Example: Solve a GeeTest v3 challenge with the async client. +"""Example: Solve GeeTest v3 through your own proxy. + +What it does: + This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. + STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. -NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a -real endpoint -- this script will not run end-to-end as-is. Replace it with a request -to your actual target page (or wherever it exposes a fresh `challenge` value) before -running this example. It's here only to illustrate where that fetch belongs in the flow. + NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a + real endpoint -- this script will not run end-to-end as-is. Replace it with a request + to your actual target page (or wherever it exposes a fresh `challenge` value) before + running this example. It's here only to illustrate where that fetch belongs in the flow. """ import asyncio @@ -43,7 +51,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 1d9ffec..82521c7 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -1,15 +1,23 @@ -""" -Example: Solve a GeeTest v3 challenge with the async client. +"""Example: Solve GeeTest v3 without a proxy. + +What it does: + This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. + STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. -NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a -real endpoint -- this script will not run end-to-end as-is. Replace it with a request -to your actual target page (or wherever it exposes a fresh `challenge` value) before -running this example. It's here only to illustrate where that fetch belongs in the flow. + NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a + real endpoint -- this script will not run end-to-end as-is. Replace it with a request + to your actual target page (or wherever it exposes a fresh `challenge` value) before + running this example. It's here only to illustrate where that fetch belongs in the flow. """ import asyncio @@ -43,7 +51,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index 506af84..eb08452 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a GeeTest v4 challenge with the async client. +"""Example: Solve GeeTest v4 through your own proxy. + +What it does: + This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. + STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -33,7 +41,7 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 5668b8d..9f4f16f 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a GeeTest v4 challenge with the async client. +"""Example: Solve GeeTest v4 without a proxy. + +What it does: + This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. + STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -33,7 +41,7 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: # --- Proxyless example --- # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index db6fb9a..766972d 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -1,5 +1,13 @@ -""" -Example: Solve an image captcha with the async client. +"""Example: Recognize text in bundled local captcha images without a proxy. + +What it does: + This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and AsyncCaptchaClient.solve(), returning the recognized text. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. + STEP-03 - Create ImageToTextTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -41,7 +49,7 @@ def encode_image(filename): async def main(): # Image to Text tasks are usually fast. Default timeout is fine. - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: digits_body = encode_image("captcha-digits.png") # --- Basic example --- diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 4389924..83e4b46 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +"""Example: Solve reCAPTCHA v2 enterprise through your own proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. + STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index 10d157f..abb0678 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. +"""Example: Solve reCAPTCHA v2 enterprise without a proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. + STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. # Enterprise captchas are loaded via the reCAPTCHA Enterprise API. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 6cd87d9..2f04297 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 challenge through your own proxy with the async client. +"""Example: Solve reCAPTCHA v2 through your own proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. + STEP-03 - Create RecaptchaV2Task and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -32,7 +40,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. # Use when the target site is geo-restricted or you need session consistency. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index 01d2626..33a2f40 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 challenge without a proxy with the async client. +"""Example: Solve reCAPTCHA v2 without a proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. + STEP-03 - Create RecaptchaV2TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -31,7 +39,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. The service uses its own IP addresses. try: diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index d4bb2a7..daaa07f 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v3 challenge with the async client. +"""Example: Solve score-based reCAPTCHA v3 without a proxy. + +What it does: + This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. + STEP-03 - Create RecaptchaV3TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -32,7 +40,7 @@ async def main(): # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=180) as solver: + async with AsyncCaptchaClient(api_key, timeout=180, debug=True) as solver: # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index c92644e..c50224e 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Tencent captcha challenge with the async client. +"""Example: Solve Tencent captcha through your own proxy. + +What it does: + This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. + STEP-03 - Create TencentTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- With proxy example --- # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index a840450..c6b7dc4 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Tencent captcha challenge with the async client. +"""Example: Solve Tencent captcha without a proxy. + +What it does: + This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. + STEP-03 - Create TencentTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Proxyless example --- # Solves Tencent captcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index f46b797..c1b193b 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Cloudflare Turnstile challenge with the async client. +"""Example: Solve Cloudflare turnstile through your own proxy. + +What it does: + This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and AsyncCaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. + STEP-03 - Create TurnstileTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 76dd7f2..a9ec253 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Cloudflare Turnstile challenge with the async client. +"""Example: Solve Cloudflare turnstile without a proxy. + +What it does: + This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and AsyncCaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. + STEP-03 - Create TurnstileTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -30,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. # The token is tied to the User-Agent. If you pass userAgent, use the same diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index a89202c..3d97c83 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -1,4 +1,13 @@ -"""Example: Solve an image-based Yandex SmartCaptcha asynchronously. +"""Example: Solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. + +What it does: + This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. + STEP-03 - Create YandexSmartCaptchaImageTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -35,7 +44,7 @@ def encode_image(filename: str) -> str: async def main() -> None: api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: result = await solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), diff --git a/examples/async/yandex_smartcaptcha_kaleidoscope.py b/examples/async/yandex_smartcaptcha_kaleidoscope.py index e49a799..6c3cf13 100644 --- a/examples/async/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/async/yandex_smartcaptcha_kaleidoscope.py @@ -1,15 +1,13 @@ -"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope asynchronously. +"""Example: Solve a Yandex smartcaptcha kaleidoscope puzzle from a bundled local image without a proxy. -This example reads the bundled Kaleidoscope challenge image, encodes it as -Base64, sends it together with the puzzle-step sequence without a proxy, and -prints how many times to click the slider arrow. It uses -YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve(). +What it does: + This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve(), returning the number of slider-arrow clicks. How it works: -STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge image. -STEP-02 - Encode the image and create a task with the captured puzzle steps. -STEP-03 - Await solve(), which creates the task and polls for its solution. -STEP-04 - Print the slider-arrow click count, or report the error. + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. + STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -47,7 +45,7 @@ def encode_image(filename: str) -> str: async def main() -> None: # STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge image. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # STEP-02: Encode the image and create a task with the captured puzzle steps. # STEP-03: Await solve(), which creates the task and polls for its solution. clicks = await solver.solve( diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 5cae19b..afbda9a 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +"""Example: Solve token-based Yandex smartcaptcha through your own proxy. + +What it does: + This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and AsyncCaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. + STEP-03 - Create YandexSmartCaptchaTask and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -29,7 +37,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index 9537797..a3c89ef 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. +"""Example: Solve token-based Yandex smartcaptcha without a proxy. + +What it does: + This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and AsyncCaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. + STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -29,7 +37,7 @@ async def main(): - async with AsyncCaptchaClient(api_key) as solver: + async with AsyncCaptchaClient(api_key, debug=True) as solver: # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index 5cfa72b..5afdf08 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -1,5 +1,12 @@ -""" -Example: Get account balance. +"""Example: Check the current captcha solver account balance without creating a captcha task. + +What it does: + This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses CaptchaClient.get_balance() and returns the account balance. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Call solver.get_balance(); this does not create or poll a CAPTCHA task. + STEP-03 - Print the balance returned by the API. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -32,7 +39,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # Get the current account balance. # Returns a float with the available amount in your account currency. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index 32a2fd5..b059c70 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -1,5 +1,13 @@ -""" -Example: Solve a click-based image captcha using CoordinatesTask. +"""Example: Solve click-based image captchas from bundled local images without a proxy. + +What it does: + This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and CaptchaClient.solve(), returning pixel coordinates to click. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. + STEP-03 - Create CoordinatesTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -37,7 +45,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py deleted file mode 100644 index 4ff70e2..0000000 --- a/examples/sync/debug_mode.py +++ /dev/null @@ -1,51 +0,0 @@ -"""Run one Image to Text task with sanitized debug logging enabled. - -This example reads a bundled image as Base64, enables the SDK's opt-in debug -mode, solves the image task, and prints the recognized -text after the sanitized request/response events and SOLVE SUMMARY. It uses -ImageToTextTask and CaptchaClient.solve(). - -This creates a real, paid CAPTCHA task. Set CAPTCHA_API_KEY in the environment -or in the repository's .env file before running it. - -How it works: -STEP-01 - Read the bundled image and create CaptchaClient with debug logging enabled. -STEP-02 - Create ImageToTextTask and call solve(). -STEP-03 - Inspect the sanitized debug events and SOLVE SUMMARY. -STEP-04 - Print the recognized text returned by the service. -""" - -import os -import sys -from base64 import b64encode - -try: - from dotenv import load_dotenv -except ModuleNotFoundError as exc: - if exc.name != "dotenv": - raise - load_dotenv = None - -repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) -sys.path.append(repo_root) -if load_dotenv is not None: - load_dotenv(os.path.join(repo_root, ".env")) - -from captcha_solver_api import CaptchaClient -from captcha_solver_api.tasks import ImageToTextTask - -# STEP-01: Read the bundled image and create CaptchaClient with debug enabled. -api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") - -with open(image_path, "rb") as image_file: - image_body = b64encode(image_file.read()).decode("utf-8") - -with CaptchaClient(api_key, debug=True) as client: - # STEP-02: Create ImageToTextTask and call solve(). - solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) - -# STEP-03: Inspect the sanitized debug events and SOLVE SUMMARY. -# STEP-04: Print the recognized text returned by the service. -# The SOLVE SUMMARY is emitted before solve() returns, so this is printed last. -print(f"Recognized text: {solution['text']}") diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index f8a7835..cb39d84 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -1,15 +1,23 @@ -""" -Example: Solve a GeeTest v3 challenge. +"""Example: Solve GeeTest v3 through your own proxy. + +What it does: + This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning challenge, validate, and seccode values. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. + STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. -NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a -real endpoint -- this script will not run end-to-end as-is. Replace it with a request -to your actual target page (or wherever it exposes a fresh `challenge` value) before -running this example. It's here only to illustrate where that fetch belongs in the flow. + NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a + real endpoint -- this script will not run end-to-end as-is. Replace it with a request + to your actual target page (or wherever it exposes a fresh `challenge` value) before + running this example. It's here only to illustrate where that fetch belongs in the flow. """ import os @@ -42,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 9e61e7a..8c64a93 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -1,15 +1,23 @@ -""" -Example: Solve a GeeTest v3 challenge. +"""Example: Solve GeeTest v3 without a proxy. + +What it does: + This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning challenge, validate, and seccode values. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. + STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. -NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a -real endpoint -- this script will not run end-to-end as-is. Replace it with a request -to your actual target page (or wherever it exposes a fresh `challenge` value) before -running this example. It's here only to illustrate where that fetch belongs in the flow. + NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a + real endpoint -- this script will not run end-to-end as-is. Replace it with a request + to your actual target page (or wherever it exposes a fresh `challenge` value) before + running this example. It's here only to illustrate where that fetch belongs in the flow. """ import os @@ -42,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index f959cec..e5cd405 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a GeeTest v4 challenge. +"""Example: Solve GeeTest v4 through your own proxy. + +What it does: + This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning captcha_output and related validation fields. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. + STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -37,7 +45,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) # --- With proxy example --- # Solves GeeTest v4 through your own proxy. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index f25b5f0..eb2f5c0 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a GeeTest v4 challenge. +"""Example: Solve GeeTest v4 without a proxy. + +What it does: + This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning captcha_output and related validation fields. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. + STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -37,7 +45,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) # --- Proxyless example --- # Solves GeeTest v4 without a proxy. diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 4a449d7..8af002f 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -1,5 +1,13 @@ -""" -Example: Solve an Image to Text challenge. +"""Example: Recognize text in bundled local captcha images without a proxy. + +What it does: + This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and CaptchaClient.solve(), returning the recognized text. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. + STEP-03 - Create ImageToTextTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -37,7 +45,7 @@ # Create a solver instance with your API key. # Image to Text tasks are usually fast. Default timeout is fine. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Basic example --- # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index b788161..2020fd4 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 Enterprise challenge. +"""Example: Solve reCAPTCHA v2 enterprise through your own proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and CaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. + STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -34,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index 1bb0e1f..0d52377 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 Enterprise challenge. +"""Example: Solve reCAPTCHA v2 enterprise without a proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. + STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -34,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 0998e03..4d73bcb 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 challenge. +"""Example: Solve reCAPTCHA v2 through your own proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and CaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. + STEP-03 - Create RecaptchaV2Task and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -35,7 +43,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index 776c62e..c4dac48 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v2 challenge. +"""Example: Solve reCAPTCHA v2 without a proxy. + +What it does: + This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. + STEP-03 - Create RecaptchaV2TaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -35,7 +43,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index 0ce6775..2b6340e 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -1,5 +1,13 @@ -""" -Example: Solve a reCAPTCHA v3 challenge. +"""Example: Solve score-based reCAPTCHA v3 without a proxy. + +What it does: + This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. + STEP-03 - Create RecaptchaV3TaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -36,7 +44,7 @@ # Create a solver instance with your API key. # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=180) +solver = CaptchaClient(api_key, timeout=180, debug=True) # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 1314907..9bebf7d 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Tencent captcha challenge. +"""Example: Solve Tencent captcha through your own proxy. + +What it does: + This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. + STEP-03 - Create TencentTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -27,7 +35,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- With proxy example --- # Solves Tencent captcha through your own proxy. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index fd620bc..5d8b34b 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Tencent captcha challenge. +"""Example: Solve Tencent captcha without a proxy. + +What it does: + This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. + STEP-03 - Create TencentTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -27,7 +35,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Proxyless example --- # Solves Tencent captcha without a proxy. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 748f2e2..1802b4a 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Cloudflare Turnstile challenge. +"""Example: Solve Cloudflare turnstile through your own proxy. + +What it does: + This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and CaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. + STEP-03 - Create TurnstileTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -34,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 2a32588..5847d7d 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Cloudflare Turnstile challenge. +"""Example: Solve Cloudflare turnstile without a proxy. + +What it does: + This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and CaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. + STEP-03 - Create TurnstileTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -34,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 9973cdc..5b4206e 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -1,4 +1,13 @@ -"""Example: Solve an image-based Yandex SmartCaptcha. +"""Example: Solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. + +What it does: + This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and CaptchaClient.solve(), returning pixel coordinates to click. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. + STEP-03 - Create YandexSmartCaptchaImageTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -33,7 +42,7 @@ def encode_image(filename: str) -> str: api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) try: result = solver.solve( diff --git a/examples/sync/yandex_smartcaptcha_kaleidoscope.py b/examples/sync/yandex_smartcaptcha_kaleidoscope.py index 694e2f9..1236227 100644 --- a/examples/sync/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/sync/yandex_smartcaptcha_kaleidoscope.py @@ -1,15 +1,13 @@ -"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope puzzle. +"""Example: Solve a Yandex smartcaptcha kaleidoscope puzzle from a bundled local image without a proxy. -This example reads the bundled Kaleidoscope challenge image, encodes it as -Base64, sends it together with the puzzle-step sequence without a proxy, and -prints how many times to click the slider arrow. It uses -YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve(). +What it does: + This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve(), returning the number of slider-arrow clicks. How it works: -STEP-01 - Configure CaptchaClient and locate the bundled challenge image. -STEP-02 - Encode the image and create a task with the captured puzzle steps. -STEP-03 - Call solve(), which creates the task and polls for its solution. -STEP-04 - Print the slider-arrow click count, or report the error. + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. + STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -45,7 +43,7 @@ def encode_image(filename: str) -> str: # STEP-01: Configure CaptchaClient and locate the bundled challenge image. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) try: # STEP-02: Encode the image and create a task with the captured puzzle steps. diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 08a2fc5..6021911 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Yandex SmartCaptcha challenge (token-based). +"""Example: Solve token-based Yandex smartcaptcha through your own proxy. + +What it does: + This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and CaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. + STEP-03 - Create YandexSmartCaptchaTask and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -26,7 +34,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index af1b089..943574b 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -1,5 +1,13 @@ -""" -Example: Solve a Yandex SmartCaptcha challenge (token-based). +"""Example: Solve token-based Yandex smartcaptcha without a proxy. + +What it does: + This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and CaptchaClient.solve(), returning a token. + +How it works: + STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. + STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to solver.solve(task), which creates and polls the task. + STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. Prerequisites: Set the CAPTCHA_API_KEY environment variable. @@ -26,7 +34,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key) +solver = CaptchaClient(api_key, debug=True) # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. From 50b10514a50f0e10aae81f473113defab78fa7c4 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 18:17:00 +0300 Subject: [PATCH 16/18] fix: restore dedicated debug examples --- README.md | 14 ++++- examples/README.md | 11 +++- examples/async/balance.py | 4 +- examples/async/coordinates.py | 4 +- examples/async/debug_mode.py | 55 +++++++++++++++++++ examples/async/geetest_v3_proxy.py | 4 +- examples/async/geetest_v3_proxyless.py | 4 +- examples/async/geetest_v4_proxy.py | 4 +- examples/async/geetest_v4_proxyless.py | 4 +- examples/async/image_to_text.py | 4 +- .../async/recaptcha_v2_enterprise_proxy.py | 4 +- .../recaptcha_v2_enterprise_proxyless.py | 4 +- examples/async/recaptcha_v2_proxy.py | 4 +- examples/async/recaptcha_v2_proxyless.py | 4 +- examples/async/recaptcha_v3.py | 4 +- examples/async/tencent_proxy.py | 4 +- examples/async/tencent_proxyless.py | 4 +- examples/async/turnstile_proxy.py | 4 +- examples/async/turnstile_proxyless.py | 4 +- examples/async/yandex_smartcaptcha_image.py | 4 +- .../async/yandex_smartcaptcha_kaleidoscope.py | 4 +- examples/async/yandex_smartcaptcha_proxy.py | 4 +- .../async/yandex_smartcaptcha_proxyless.py | 4 +- examples/sync/balance.py | 4 +- examples/sync/coordinates.py | 4 +- examples/sync/debug_mode.py | 47 ++++++++++++++++ examples/sync/geetest_v3_proxy.py | 4 +- examples/sync/geetest_v3_proxyless.py | 4 +- examples/sync/geetest_v4_proxy.py | 4 +- examples/sync/geetest_v4_proxyless.py | 4 +- examples/sync/image_to_text.py | 4 +- .../sync/recaptcha_v2_enterprise_proxy.py | 4 +- .../sync/recaptcha_v2_enterprise_proxyless.py | 4 +- examples/sync/recaptcha_v2_proxy.py | 4 +- examples/sync/recaptcha_v2_proxyless.py | 4 +- examples/sync/recaptcha_v3.py | 4 +- examples/sync/tencent_proxy.py | 4 +- examples/sync/tencent_proxyless.py | 4 +- examples/sync/turnstile_proxy.py | 4 +- examples/sync/turnstile_proxyless.py | 4 +- examples/sync/yandex_smartcaptcha_image.py | 4 +- .../sync/yandex_smartcaptcha_kaleidoscope.py | 4 +- examples/sync/yandex_smartcaptcha_proxy.py | 4 +- .../sync/yandex_smartcaptcha_proxyless.py | 4 +- 44 files changed, 202 insertions(+), 85 deletions(-) create mode 100644 examples/async/debug_mode.py create mode 100644 examples/sync/debug_mode.py diff --git a/README.md b/README.md index 7060349..7e3b3dd 100644 --- a/README.md +++ b/README.md @@ -706,9 +706,17 @@ their first and last 40 characters plus the original length. The SDK does not lo URLs and custom task fields can still contain application data, so review logs before sharing them publicly. -All synchronous and asynchronous examples enable debug mode. They read -`CAPTCHA_API_KEY` from the environment or `.env` and create real paid CAPTCHA -tasks unless their description says otherwise. +Dedicated synchronous and asynchronous examples demonstrate debug mode: + +```bash +python examples/sync/debug_mode.py +python examples/async/debug_mode.py +``` + +Examples read `CAPTCHA_API_KEY` from the environment or `.env`. They create real paid CAPTCHA +tasks unless their description says otherwise. See +[`examples/sync/debug_mode.py`](examples/sync/debug_mode.py) and +[`examples/async/debug_mode.py`](examples/async/debug_mode.py). ### Custom timeout and polling diff --git a/examples/README.md b/examples/README.md index b09e5f8..7d14fb7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -82,8 +82,15 @@ python examples/sync/yandex_smartcaptcha_kaleidoscope.py python examples/async/recaptcha_v2_proxyless.py ``` -Every example enables `debug=True`, so running any sync or async script shows -sanitized SDK request, response, timing, polling, error, and solve-summary logs. +Use the dedicated sync or async example to see sanitized SDK request, response, +timing, polling, error, and solve-summary logs: + +```bash +python examples/sync/debug_mode.py +python examples/async/debug_mode.py +``` + +Both examples enable debug mode directly with `debug=True`. Async scripts create an `AsyncCaptchaClient` and await the same operations as the synchronous client. For several captchas, see the parallel solving pattern in the main [README](../README.md#solving-multiple-captchas-in-parallel). diff --git a/examples/async/balance.py b/examples/async/balance.py index cf77ed6..7d2b0e8 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -4,7 +4,7 @@ This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses AsyncCaptchaClient.get_balance() and returns the account balance. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Call await solver.get_balance(); this does not create or poll a CAPTCHA task. STEP-03 - Print the balance returned by the API. @@ -41,7 +41,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # Get the current account balance. # Returns a float with the available amount in your account currency. try: diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 14c819d..7a4c8dc 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -4,7 +4,7 @@ This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. STEP-03 - Create CoordinatesTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. @@ -41,7 +41,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with # a hint for the worker. The worker will click on the specified points on the image. diff --git a/examples/async/debug_mode.py b/examples/async/debug_mode.py new file mode 100644 index 0000000..cbdd201 --- /dev/null +++ b/examples/async/debug_mode.py @@ -0,0 +1,55 @@ +"""Example: Run one Image to Text task with sanitized async debug logging enabled. + +What it does: + This example reads a bundled CAPTCHA image, enables debug mode explicitly, + solves it with ImageToTextTask and AsyncCaptchaClient.solve(), and prints the + recognized text after the diagnostic events and SOLVE SUMMARY. + +How it works: + STEP-01 - Configure AsyncCaptchaClient with debug=True and read the bundled image. + STEP-02 - Encode the image and create ImageToTextTask. + STEP-03 - Await solve(), which creates and polls the task while logging safely. + STEP-04 - Inspect the sanitized logs and print the recognized text. + +Prerequisites: + Set the CAPTCHA_API_KEY environment variable or add it to the repository .env. + This example creates a real, paid CAPTCHA task. +""" + +import asyncio +import os +import sys +from base64 import b64encode + +try: + from dotenv import load_dotenv +except ModuleNotFoundError as exc: + if exc.name != "dotenv": + raise + load_dotenv = None + +repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +sys.path.append(repo_root) +if load_dotenv is not None: + load_dotenv(os.path.join(repo_root, ".env")) + +from captcha_solver_api import AsyncCaptchaClient +from captcha_solver_api.tasks import ImageToTextTask + + +async def main() -> None: + api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") + image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") + + with open(image_path, "rb") as image_file: + image_body = b64encode(image_file.read()).decode("utf-8") + + async with AsyncCaptchaClient(api_key, debug=True) as client: + solution = await client.solve( + ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6) + ) + + print(f"Recognized text: {solution['text']}") + + +asyncio.run(main()) diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index 32215da..aa50051 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. @@ -51,7 +51,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 82521c7..854f9c9 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. @@ -51,7 +51,7 @@ async def main(): Below is an example of fetching it from a demo endpoint. """ # GeeTest tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # Fetch a fresh challenge value from the target page. # In production, extract this from the page's initGeetest call or network requests. # "target-site.com" is a placeholder -- point this at your real target before running. diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index eb08452..bfdda7f 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. @@ -41,7 +41,7 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # --- With proxy example --- # Solves GeeTest v4 through your own proxy. try: diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index 9f4f16f..caec4f2 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. @@ -41,7 +41,7 @@ async def main(): # GeeTest v4 tasks may take longer. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) as solver: + async with AsyncCaptchaClient(api_key, timeout=300, polling_interval=10) as solver: # --- Proxyless example --- # Solves GeeTest v4 without a proxy. # v4 drops gt/challenge. The widget is identified by captcha_id inside initParameters. diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 766972d..48a706d 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -4,7 +4,7 @@ This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and AsyncCaptchaClient.solve(), returning the recognized text. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. STEP-03 - Create ImageToTextTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. @@ -49,7 +49,7 @@ def encode_image(filename): async def main(): # Image to Text tasks are usually fast. Default timeout is fine. - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: digits_body = encode_image("captcha-digits.png") # --- Basic example --- diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 83e4b46..275f632 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index abb0678..4d6cfe2 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. # Enterprise captchas are loaded via the reCAPTCHA Enterprise API. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index 2f04297..bab697f 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. STEP-03 - Create RecaptchaV2Task and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -40,7 +40,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. # Use when the target site is geo-restricted or you need session consistency. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index 33a2f40..f327978 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. STEP-03 - Create RecaptchaV2TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -39,7 +39,7 @@ async def main(): # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. The service uses its own IP addresses. try: diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index daaa07f..e606d0d 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -4,7 +4,7 @@ This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. STEP-03 - Create RecaptchaV3TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -40,7 +40,7 @@ async def main(): # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. - async with AsyncCaptchaClient(api_key, timeout=180, debug=True) as solver: + async with AsyncCaptchaClient(api_key, timeout=180) as solver: # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. # minScore values: 0.3 (fastest), 0.7 (balanced), 0.9 (highest, slowest). diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index c50224e..d62943b 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. STEP-03 - Create TencentTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Tencent captcha through your own proxy. # Use when the target site is geo-restricted or you need a consistent session. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index c6b7dc4..55ceaec 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. STEP-03 - Create TencentTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Tencent captcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index c1b193b..56b6874 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and AsyncCaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. STEP-03 - Create TurnstileTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. try: diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index a9ec253..243b5e8 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and AsyncCaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. STEP-03 - Create TurnstileTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -38,7 +38,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. # The token is tied to the User-Agent. If you pass userAgent, use the same diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index 3d97c83..6fa40aa 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -4,7 +4,7 @@ This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. STEP-03 - Create YandexSmartCaptchaImageTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. @@ -44,7 +44,7 @@ def encode_image(filename: str) -> str: async def main() -> None: api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: result = await solver.solve( YandexSmartCaptchaImageTask( image=encode_image("yandex-smartcaptcha-image.png"), diff --git a/examples/async/yandex_smartcaptcha_kaleidoscope.py b/examples/async/yandex_smartcaptcha_kaleidoscope.py index 6c3cf13..431d27c 100644 --- a/examples/async/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/async/yandex_smartcaptcha_kaleidoscope.py @@ -4,7 +4,7 @@ This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve(), returning the number of slider-arrow clicks. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. @@ -45,7 +45,7 @@ def encode_image(filename: str) -> str: async def main() -> None: # STEP-01: Configure AsyncCaptchaClient and locate the bundled challenge image. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # STEP-02: Encode the image and create a task with the captured puzzle steps. # STEP-03: Await solve(), which creates the task and polls for its solution. clicks = await solver.solve( diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index afbda9a..379b8f8 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and AsyncCaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. STEP-03 - Create YandexSmartCaptchaTask and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -37,7 +37,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. # Note: this is the only captcha type where an https proxy is accepted. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index a3c89ef..1899a24 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and AsyncCaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key and debug logging. + STEP-01 - Configure AsyncCaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -37,7 +37,7 @@ async def main(): - async with AsyncCaptchaClient(api_key, debug=True) as solver: + async with AsyncCaptchaClient(api_key) as solver: # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. # The service's own proxies are used to solve the captcha. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index 5afdf08..f29f826 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -4,7 +4,7 @@ This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses CaptchaClient.get_balance() and returns the account balance. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Call solver.get_balance(); this does not create or poll a CAPTCHA task. STEP-03 - Print the balance returned by the API. @@ -39,7 +39,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # Get the current account balance. # Returns a float with the available amount in your account currency. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index b059c70..97eee72 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -4,7 +4,7 @@ This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and CaptchaClient.solve(), returning pixel coordinates to click. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. STEP-03 - Create CoordinatesTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. @@ -45,7 +45,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Basic example --- # Solves a simple click-based captcha (examples/assets/fruit-click.png) with diff --git a/examples/sync/debug_mode.py b/examples/sync/debug_mode.py new file mode 100644 index 0000000..583e67c --- /dev/null +++ b/examples/sync/debug_mode.py @@ -0,0 +1,47 @@ +"""Example: Run one Image to Text task with sanitized debug logging enabled. + +What it does: + This example reads a bundled CAPTCHA image, enables debug mode explicitly, + solves it with ImageToTextTask and CaptchaClient.solve(), and prints the + recognized text after the diagnostic events and SOLVE SUMMARY. + +How it works: + STEP-01 - Configure CaptchaClient with debug=True and read the bundled image. + STEP-02 - Encode the image and create ImageToTextTask. + STEP-03 - Call solve(), which creates and polls the task while logging safely. + STEP-04 - Inspect the sanitized logs and print the recognized text. + +Prerequisites: + Set the CAPTCHA_API_KEY environment variable or add it to the repository .env. + This example creates a real, paid CAPTCHA task. +""" + +import os +import sys +from base64 import b64encode + +try: + from dotenv import load_dotenv +except ModuleNotFoundError as exc: + if exc.name != "dotenv": + raise + load_dotenv = None + +repo_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +sys.path.append(repo_root) +if load_dotenv is not None: + load_dotenv(os.path.join(repo_root, ".env")) + +from captcha_solver_api import CaptchaClient +from captcha_solver_api.tasks import ImageToTextTask + +api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") +image_path = os.path.join(repo_root, "examples", "assets", "captcha-digits.png") + +with open(image_path, "rb") as image_file: + image_body = b64encode(image_file.read()).decode("utf-8") + +with CaptchaClient(api_key, debug=True) as client: + solution = client.solve(ImageToTextTask(body=image_body, numeric=1, minLength=4, maxLength=6)) + +print(f"Recognized text: {solution['text']}") diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index cb39d84..d750b27 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning challenge, validate, and seccode values. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. @@ -50,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index 8c64a93..d0c8b7e 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning challenge, validate, and seccode values. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. @@ -50,7 +50,7 @@ # Create a solver instance with your API key. # GeeTest tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) """ Important: the value of the 'challenge' parameter is dynamic. diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index e5cd405..dc5234b 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning captcha_output and related validation fields. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. @@ -45,7 +45,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) # --- With proxy example --- # Solves GeeTest v4 through your own proxy. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index eb2f5c0..9cd765d 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning captcha_output and related validation fields. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. @@ -45,7 +45,7 @@ # Create a solver instance with your API key. # GeeTest v4 tasks may take longer. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=300, polling_interval=10, debug=True) +solver = CaptchaClient(api_key, timeout=300, polling_interval=10) # --- Proxyless example --- # Solves GeeTest v4 without a proxy. diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 8af002f..2d4436b 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -4,7 +4,7 @@ This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and CaptchaClient.solve(), returning the recognized text. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. STEP-03 - Create ImageToTextTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. @@ -45,7 +45,7 @@ # Create a solver instance with your API key. # Image to Text tasks are usually fast. Default timeout is fine. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Basic example --- # Solves a simple 5-digit image captcha (examples/assets/captcha-digits.png) diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index 2020fd4..4993fe6 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and CaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -42,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves reCAPTCHA v2 Enterprise through your own proxy. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index 0d52377..5925688 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -42,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves reCAPTCHA v2 Enterprise without a proxy. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index 4d73bcb..ee6a21c 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and CaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. STEP-03 - Create RecaptchaV2Task and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -43,7 +43,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves reCAPTCHA v2 through your own proxy. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index c4dac48..a0747dd 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. STEP-03 - Create RecaptchaV2TaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -43,7 +43,7 @@ # Create a solver instance with your API key. # Optional: timeout (max seconds to wait for solution, default 120) # Optional: polling_interval (seconds before and between status checks, default 10) -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves reCAPTCHA v2 without a proxy. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index 2b6340e..69bc555 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -4,7 +4,7 @@ This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. STEP-03 - Create RecaptchaV3TaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. @@ -44,7 +44,7 @@ # Create a solver instance with your API key. # reCAPTCHA v3 tasks may take longer to solve. Increase timeout if needed. -solver = CaptchaClient(api_key, timeout=180, debug=True) +solver = CaptchaClient(api_key, timeout=180) # reCAPTCHA v3 returns a score instead of a pass/fail challenge. # The higher the minScore you request, the harder and longer the task takes. diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 9bebf7d..48a6288 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. STEP-03 - Create TencentTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. @@ -35,7 +35,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Tencent captcha through your own proxy. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 5d8b34b..1b0a3e7 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. STEP-03 - Create TencentTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. @@ -35,7 +35,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Tencent captcha without a proxy. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index 1802b4a..bd3d268 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and CaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. STEP-03 - Create TurnstileTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -42,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Cloudflare Turnstile through your own proxy. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index 5847d7d..c5719a7 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and CaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. STEP-03 - Create TurnstileTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -42,7 +42,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") # Create a solver instance with your API key. -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Cloudflare Turnstile without a proxy. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index 5b4206e..be93a52 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -4,7 +4,7 @@ This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and CaptchaClient.solve(), returning pixel coordinates to click. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. STEP-03 - Create YandexSmartCaptchaImageTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. @@ -42,7 +42,7 @@ def encode_image(filename: str) -> str: api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) try: result = solver.solve( diff --git a/examples/sync/yandex_smartcaptcha_kaleidoscope.py b/examples/sync/yandex_smartcaptcha_kaleidoscope.py index 1236227..600b34f 100644 --- a/examples/sync/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/sync/yandex_smartcaptcha_kaleidoscope.py @@ -4,7 +4,7 @@ This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve(), returning the number of slider-arrow clicks. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. @@ -43,7 +43,7 @@ def encode_image(filename: str) -> str: # STEP-01: Configure CaptchaClient and locate the bundled challenge image. api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) try: # STEP-02: Encode the image and create a task with the captured puzzle steps. diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 6021911..52bbeeb 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -4,7 +4,7 @@ This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and CaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. STEP-03 - Create YandexSmartCaptchaTask and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -34,7 +34,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- With proxy example --- # Solves Yandex SmartCaptcha through your own proxy. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index 943574b..87a979d 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -4,7 +4,7 @@ This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and CaptchaClient.solve(), returning a token. How it works: - STEP-01 - Configure CaptchaClient with the API key and debug logging. + STEP-01 - Configure CaptchaClient with the API key. STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to solver.solve(task), which creates and polls the task. STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. @@ -34,7 +34,7 @@ api_key = os.getenv("CAPTCHA_API_KEY", "YOUR_API_KEY") -solver = CaptchaClient(api_key, debug=True) +solver = CaptchaClient(api_key) # --- Proxyless example --- # Solves Yandex SmartCaptcha without a proxy. From ef21735546e9a8d848e54be919705458ea9f8208 Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 18:21:02 +0300 Subject: [PATCH 17/18] docs: restore coordinates task description --- captcha_solver_api/tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/captcha_solver_api/tasks.py b/captcha_solver_api/tasks.py index bf6549d..38142d9 100644 --- a/captcha_solver_api/tasks.py +++ b/captcha_solver_api/tasks.py @@ -847,8 +847,7 @@ class CoordinatesTask(BaseTask): comment: Optional. Hint for the worker, e.g. `"click on the green apple"`. Recommended for generic click captchas. imgInstructions: Optional. Optional instruction image, base64-encoded. - minClicks: Optional. Minimum number of clicks expected. When unset, the - field is omitted and the API applies its default. + minClicks: Optional. Minimum number of clicks expected (default `1`). maxClicks: Optional. Maximum number of clicks allowed. Returns (`solution` from `solve()`): From f4a27be09ed4426b6fe4fac40d3a98e80932799b Mon Sep 17 00:00:00 2001 From: dariyaanis Date: Wed, 18 Nov 2026 18:22:27 +0300 Subject: [PATCH 18/18] docs: restore regular examples after review --- examples/async/balance.py | 11 ++-------- examples/async/coordinates.py | 12 ++--------- examples/async/geetest_v3_proxy.py | 20 ++++++------------- examples/async/geetest_v3_proxyless.py | 20 ++++++------------- examples/async/geetest_v4_proxy.py | 12 ++--------- examples/async/geetest_v4_proxyless.py | 12 ++--------- examples/async/image_to_text.py | 12 ++--------- .../async/recaptcha_v2_enterprise_proxy.py | 12 ++--------- .../recaptcha_v2_enterprise_proxyless.py | 12 ++--------- examples/async/recaptcha_v2_proxy.py | 12 ++--------- examples/async/recaptcha_v2_proxyless.py | 12 ++--------- examples/async/recaptcha_v3.py | 12 ++--------- examples/async/tencent_proxy.py | 12 ++--------- examples/async/tencent_proxyless.py | 12 ++--------- examples/async/turnstile_proxy.py | 12 ++--------- examples/async/turnstile_proxyless.py | 12 ++--------- examples/async/yandex_smartcaptcha_image.py | 11 +--------- .../async/yandex_smartcaptcha_kaleidoscope.py | 16 ++++++++------- examples/async/yandex_smartcaptcha_proxy.py | 12 ++--------- .../async/yandex_smartcaptcha_proxyless.py | 12 ++--------- examples/sync/balance.py | 11 ++-------- examples/sync/coordinates.py | 12 ++--------- examples/sync/geetest_v3_proxy.py | 20 ++++++------------- examples/sync/geetest_v3_proxyless.py | 20 ++++++------------- examples/sync/geetest_v4_proxy.py | 12 ++--------- examples/sync/geetest_v4_proxyless.py | 12 ++--------- examples/sync/image_to_text.py | 12 ++--------- .../sync/recaptcha_v2_enterprise_proxy.py | 12 ++--------- .../sync/recaptcha_v2_enterprise_proxyless.py | 12 ++--------- examples/sync/recaptcha_v2_proxy.py | 12 ++--------- examples/sync/recaptcha_v2_proxyless.py | 12 ++--------- examples/sync/recaptcha_v3.py | 12 ++--------- examples/sync/tencent_proxy.py | 12 ++--------- examples/sync/tencent_proxyless.py | 12 ++--------- examples/sync/turnstile_proxy.py | 12 ++--------- examples/sync/turnstile_proxyless.py | 12 ++--------- examples/sync/yandex_smartcaptcha_image.py | 11 +--------- .../sync/yandex_smartcaptcha_kaleidoscope.py | 16 ++++++++------- examples/sync/yandex_smartcaptcha_proxy.py | 12 ++--------- .../sync/yandex_smartcaptcha_proxyless.py | 12 ++--------- 40 files changed, 108 insertions(+), 408 deletions(-) diff --git a/examples/async/balance.py b/examples/async/balance.py index 7d2b0e8..d1d9d78 100644 --- a/examples/async/balance.py +++ b/examples/async/balance.py @@ -1,12 +1,5 @@ -"""Example: Check the current captcha solver account balance without creating a captcha task. - -What it does: - This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses AsyncCaptchaClient.get_balance() and returns the account balance. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Call await solver.get_balance(); this does not create or poll a CAPTCHA task. - STEP-03 - Print the balance returned by the API. +""" +Example: Get account balance with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/coordinates.py b/examples/async/coordinates.py index 7a4c8dc..70663b6 100644 --- a/examples/async/coordinates.py +++ b/examples/async/coordinates.py @@ -1,13 +1,5 @@ -"""Example: Solve click-based image captchas from bundled local images without a proxy. - -What it does: - This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. - STEP-03 - Create CoordinatesTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a click-based image captcha using CoordinatesTask with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/geetest_v3_proxy.py b/examples/async/geetest_v3_proxy.py index aa50051..ce6bc1e 100644 --- a/examples/async/geetest_v3_proxy.py +++ b/examples/async/geetest_v3_proxy.py @@ -1,23 +1,15 @@ -"""Example: Solve GeeTest v3 through your own proxy. - -What it does: - This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. - STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v3 challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. - NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a - real endpoint -- this script will not run end-to-end as-is. Replace it with a request - to your actual target page (or wherever it exposes a fresh `challenge` value) before - running this example. It's here only to illustrate where that fetch belongs in the flow. +NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a +real endpoint -- this script will not run end-to-end as-is. Replace it with a request +to your actual target page (or wherever it exposes a fresh `challenge` value) before +running this example. It's here only to illustrate where that fetch belongs in the flow. """ import asyncio diff --git a/examples/async/geetest_v3_proxyless.py b/examples/async/geetest_v3_proxyless.py index 854f9c9..1d9ffec 100644 --- a/examples/async/geetest_v3_proxyless.py +++ b/examples/async/geetest_v3_proxyless.py @@ -1,23 +1,15 @@ -"""Example: Solve GeeTest v3 without a proxy. - -What it does: - This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning challenge, validate, and seccode values. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. - STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v3 challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. - NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a - real endpoint -- this script will not run end-to-end as-is. Replace it with a request - to your actual target page (or wherever it exposes a fresh `challenge` value) before - running this example. It's here only to illustrate where that fetch belongs in the flow. +NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a +real endpoint -- this script will not run end-to-end as-is. Replace it with a request +to your actual target page (or wherever it exposes a fresh `challenge` value) before +running this example. It's here only to illustrate where that fetch belongs in the flow. """ import asyncio diff --git a/examples/async/geetest_v4_proxy.py b/examples/async/geetest_v4_proxy.py index bfdda7f..506af84 100644 --- a/examples/async/geetest_v4_proxy.py +++ b/examples/async/geetest_v4_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve GeeTest v4 through your own proxy. - -What it does: - This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. - STEP-03 - Create GeeTestTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v4 challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/geetest_v4_proxyless.py b/examples/async/geetest_v4_proxyless.py index caec4f2..5668b8d 100644 --- a/examples/async/geetest_v4_proxyless.py +++ b/examples/async/geetest_v4_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve GeeTest v4 without a proxy. - -What it does: - This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and AsyncCaptchaClient.solve(), returning captcha_output and related validation fields. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. - STEP-03 - Create GeeTestTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v4 challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/image_to_text.py b/examples/async/image_to_text.py index 48a706d..db6fb9a 100644 --- a/examples/async/image_to_text.py +++ b/examples/async/image_to_text.py @@ -1,13 +1,5 @@ -"""Example: Recognize text in bundled local captcha images without a proxy. - -What it does: - This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and AsyncCaptchaClient.solve(), returning the recognized text. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. - STEP-03 - Create ImageToTextTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve an image captcha with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/recaptcha_v2_enterprise_proxy.py b/examples/async/recaptcha_v2_enterprise_proxy.py index 275f632..4389924 100644 --- a/examples/async/recaptcha_v2_enterprise_proxy.py +++ b/examples/async/recaptcha_v2_enterprise_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 enterprise through your own proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. - STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/recaptcha_v2_enterprise_proxyless.py b/examples/async/recaptcha_v2_enterprise_proxyless.py index 4d6cfe2..10d157f 100644 --- a/examples/async/recaptcha_v2_enterprise_proxyless.py +++ b/examples/async/recaptcha_v2_enterprise_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 enterprise without a proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. - STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 Enterprise challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/recaptcha_v2_proxy.py b/examples/async/recaptcha_v2_proxy.py index bab697f..6cd87d9 100644 --- a/examples/async/recaptcha_v2_proxy.py +++ b/examples/async/recaptcha_v2_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 through your own proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. - STEP-03 - Create RecaptchaV2Task and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 challenge through your own proxy with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/recaptcha_v2_proxyless.py b/examples/async/recaptcha_v2_proxyless.py index f327978..01d2626 100644 --- a/examples/async/recaptcha_v2_proxyless.py +++ b/examples/async/recaptcha_v2_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 without a proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. - STEP-03 - Create RecaptchaV2TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 challenge without a proxy with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/recaptcha_v3.py b/examples/async/recaptcha_v3.py index e606d0d..d4bb2a7 100644 --- a/examples/async/recaptcha_v3.py +++ b/examples/async/recaptcha_v3.py @@ -1,13 +1,5 @@ -"""Example: Solve score-based reCAPTCHA v3 without a proxy. - -What it does: - This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and AsyncCaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. - STEP-03 - Create RecaptchaV3TaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v3 challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/tencent_proxy.py b/examples/async/tencent_proxy.py index d62943b..c92644e 100644 --- a/examples/async/tencent_proxy.py +++ b/examples/async/tencent_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve Tencent captcha through your own proxy. - -What it does: - This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. - STEP-03 - Create TencentTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Tencent captcha challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/tencent_proxyless.py b/examples/async/tencent_proxyless.py index 55ceaec..a840450 100644 --- a/examples/async/tencent_proxyless.py +++ b/examples/async/tencent_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve Tencent captcha without a proxy. - -What it does: - This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and AsyncCaptchaClient.solve(), returning appid, ret, ticket, and randstr values. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. - STEP-03 - Create TencentTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Tencent captcha challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/turnstile_proxy.py b/examples/async/turnstile_proxy.py index 56b6874..f46b797 100644 --- a/examples/async/turnstile_proxy.py +++ b/examples/async/turnstile_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve Cloudflare turnstile through your own proxy. - -What it does: - This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and AsyncCaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. - STEP-03 - Create TurnstileTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Cloudflare Turnstile challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/turnstile_proxyless.py b/examples/async/turnstile_proxyless.py index 243b5e8..76dd7f2 100644 --- a/examples/async/turnstile_proxyless.py +++ b/examples/async/turnstile_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve Cloudflare turnstile without a proxy. - -What it does: - This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and AsyncCaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. - STEP-03 - Create TurnstileTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Cloudflare Turnstile challenge with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/yandex_smartcaptcha_image.py b/examples/async/yandex_smartcaptcha_image.py index 6fa40aa..a89202c 100644 --- a/examples/async/yandex_smartcaptcha_image.py +++ b/examples/async/yandex_smartcaptcha_image.py @@ -1,13 +1,4 @@ -"""Example: Solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. - -What it does: - This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and AsyncCaptchaClient.solve(), returning pixel coordinates to click. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. - STEP-03 - Create YandexSmartCaptchaImageTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. +"""Example: Solve an image-based Yandex SmartCaptcha asynchronously. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/yandex_smartcaptcha_kaleidoscope.py b/examples/async/yandex_smartcaptcha_kaleidoscope.py index 431d27c..e49a799 100644 --- a/examples/async/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/async/yandex_smartcaptcha_kaleidoscope.py @@ -1,13 +1,15 @@ -"""Example: Solve a Yandex smartcaptcha kaleidoscope puzzle from a bundled local image without a proxy. +"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope asynchronously. -What it does: - This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve(), returning the number of slider-arrow clicks. +This example reads the bundled Kaleidoscope challenge image, encodes it as +Base64, sends it together with the puzzle-step sequence without a proxy, and +prints how many times to click the slider arrow. It uses +YandexSmartCaptchaKaleidoscopeTask and AsyncCaptchaClient.solve(). How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. - STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. +STEP-01 - Configure AsyncCaptchaClient and locate the bundled challenge image. +STEP-02 - Encode the image and create a task with the captured puzzle steps. +STEP-03 - Await solve(), which creates the task and polls for its solution. +STEP-04 - Print the slider-arrow click count, or report the error. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/yandex_smartcaptcha_proxy.py b/examples/async/yandex_smartcaptcha_proxy.py index 379b8f8..5cae19b 100644 --- a/examples/async/yandex_smartcaptcha_proxy.py +++ b/examples/async/yandex_smartcaptcha_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve token-based Yandex smartcaptcha through your own proxy. - -What it does: - This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and AsyncCaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. - STEP-03 - Create YandexSmartCaptchaTask and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/async/yandex_smartcaptcha_proxyless.py b/examples/async/yandex_smartcaptcha_proxyless.py index 1899a24..9537797 100644 --- a/examples/async/yandex_smartcaptcha_proxyless.py +++ b/examples/async/yandex_smartcaptcha_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve token-based Yandex smartcaptcha without a proxy. - -What it does: - This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and AsyncCaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure AsyncCaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. - STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to await solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Yandex SmartCaptcha challenge (token-based) with the async client. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/balance.py b/examples/sync/balance.py index f29f826..5cfa72b 100644 --- a/examples/sync/balance.py +++ b/examples/sync/balance.py @@ -1,12 +1,5 @@ -"""Example: Check the current captcha solver account balance without creating a captcha task. - -What it does: - This example shows how to check the current Captcha Solver account balance without creating a CAPTCHA task. It uses CaptchaClient.get_balance() and returns the account balance. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Call solver.get_balance(); this does not create or poll a CAPTCHA task. - STEP-03 - Print the balance returned by the API. +""" +Example: Get account balance. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/coordinates.py b/examples/sync/coordinates.py index 97eee72..32a2fd5 100644 --- a/examples/sync/coordinates.py +++ b/examples/sync/coordinates.py @@ -1,13 +1,5 @@ -"""Example: Solve click-based image captchas from bundled local images without a proxy. - -What it does: - This example shows how to solve click-based image CAPTCHAs from bundled local images without a proxy. It uses CoordinatesTask and CaptchaClient.solve(), returning pixel coordinates to click. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The image, optional instruction image, and click hints come from examples/assets and this file. - STEP-03 - Create CoordinatesTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a click-based image captcha using CoordinatesTask. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/geetest_v3_proxy.py b/examples/sync/geetest_v3_proxy.py index d750b27..f8a7835 100644 --- a/examples/sync/geetest_v3_proxy.py +++ b/examples/sync/geetest_v3_proxy.py @@ -1,23 +1,15 @@ -"""Example: Solve GeeTest v3 through your own proxy. - -What it does: - This example shows how to solve GeeTest v3 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning challenge, validate, and seccode values. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the GeeTest values from the target page, fetch a fresh challenge, and provide your proxy settings. - STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v3 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. - NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a - real endpoint -- this script will not run end-to-end as-is. Replace it with a request - to your actual target page (or wherever it exposes a fresh `challenge` value) before - running this example. It's here only to illustrate where that fetch belongs in the flow. +NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a +real endpoint -- this script will not run end-to-end as-is. Replace it with a request +to your actual target page (or wherever it exposes a fresh `challenge` value) before +running this example. It's here only to illustrate where that fetch belongs in the flow. """ import os diff --git a/examples/sync/geetest_v3_proxyless.py b/examples/sync/geetest_v3_proxyless.py index d0c8b7e..9e61e7a 100644 --- a/examples/sync/geetest_v3_proxyless.py +++ b/examples/sync/geetest_v3_proxyless.py @@ -1,23 +1,15 @@ -"""Example: Solve GeeTest v3 without a proxy. - -What it does: - This example shows how to solve GeeTest v3 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning challenge, validate, and seccode values. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and gt from the target page and fetch a fresh challenge for every request. - STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print challenge, validate, and seccode values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v3 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. Replace websiteURL, gt, and challenge with values from your target page. Important: the challenge value is dynamic. Fetch a fresh one for each request. - NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a - real endpoint -- this script will not run end-to-end as-is. Replace it with a request - to your actual target page (or wherever it exposes a fresh `challenge` value) before - running this example. It's here only to illustrate where that fetch belongs in the flow. +NOTE: "https://target-site.com/path/to/geetest/init" below is a PLACEHOLDER, not a +real endpoint -- this script will not run end-to-end as-is. Replace it with a request +to your actual target page (or wherever it exposes a fresh `challenge` value) before +running this example. It's here only to illustrate where that fetch belongs in the flow. """ import os diff --git a/examples/sync/geetest_v4_proxy.py b/examples/sync/geetest_v4_proxy.py index dc5234b..f959cec 100644 --- a/examples/sync/geetest_v4_proxy.py +++ b/examples/sync/geetest_v4_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve GeeTest v4 through your own proxy. - -What it does: - This example shows how to solve GeeTest v4 through your own proxy. It uses GeeTestTask and CaptchaClient.solve(), returning captcha_output and related validation fields. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page and provide your proxy settings. - STEP-03 - Create GeeTestTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v4 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/geetest_v4_proxyless.py b/examples/sync/geetest_v4_proxyless.py index 9cd765d..f25b5f0 100644 --- a/examples/sync/geetest_v4_proxyless.py +++ b/examples/sync/geetest_v4_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve GeeTest v4 without a proxy. - -What it does: - This example shows how to solve GeeTest v4 without a proxy. It uses GeeTestTaskProxyless and CaptchaClient.solve(), returning captcha_output and related validation fields. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and captcha_id from the target page. - STEP-03 - Create GeeTestTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print captcha_output and related validation fields. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a GeeTest v4 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/image_to_text.py b/examples/sync/image_to_text.py index 2d4436b..4a449d7 100644 --- a/examples/sync/image_to_text.py +++ b/examples/sync/image_to_text.py @@ -1,13 +1,5 @@ -"""Example: Recognize text in bundled local captcha images without a proxy. - -What it does: - This example shows how to recognize text in bundled local CAPTCHA images without a proxy. It uses ImageToTextTask and CaptchaClient.solve(), returning the recognized text. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The images and answer-format hints come from examples/assets and this file. - STEP-03 - Create ImageToTextTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print the recognized text. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve an Image to Text challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/recaptcha_v2_enterprise_proxy.py b/examples/sync/recaptcha_v2_enterprise_proxy.py index 4993fe6..b788161 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxy.py +++ b/examples/sync/recaptcha_v2_enterprise_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 enterprise through your own proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 Enterprise through your own proxy. It uses RecaptchaV2EnterpriseTask and CaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page, and provide your proxy settings. - STEP-03 - Create RecaptchaV2EnterpriseTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 Enterprise challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/recaptcha_v2_enterprise_proxyless.py b/examples/sync/recaptcha_v2_enterprise_proxyless.py index 5925688..1bb0e1f 100644 --- a/examples/sync/recaptcha_v2_enterprise_proxyless.py +++ b/examples/sync/recaptcha_v2_enterprise_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 enterprise without a proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 Enterprise without a proxy. It uses RecaptchaV2EnterpriseTaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any enterprisePayload from the target page. - STEP-03 - Create RecaptchaV2EnterpriseTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 Enterprise challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/recaptcha_v2_proxy.py b/examples/sync/recaptcha_v2_proxy.py index ee6a21c..0998e03 100644 --- a/examples/sync/recaptcha_v2_proxy.py +++ b/examples/sync/recaptcha_v2_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 through your own proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 through your own proxy. It uses RecaptchaV2Task and CaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. - STEP-03 - Create RecaptchaV2Task and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/recaptcha_v2_proxyless.py b/examples/sync/recaptcha_v2_proxyless.py index a0747dd..776c62e 100644 --- a/examples/sync/recaptcha_v2_proxyless.py +++ b/examples/sync/recaptcha_v2_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve reCAPTCHA v2 without a proxy. - -What it does: - This example shows how to solve reCAPTCHA v2 without a proxy. It uses RecaptchaV2TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. - STEP-03 - Create RecaptchaV2TaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v2 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/recaptcha_v3.py b/examples/sync/recaptcha_v3.py index 69bc555..0ce6775 100644 --- a/examples/sync/recaptcha_v3.py +++ b/examples/sync/recaptcha_v3.py @@ -1,13 +1,5 @@ -"""Example: Solve score-based reCAPTCHA v3 without a proxy. - -What it does: - This example shows how to solve score-based reCAPTCHA v3 without a proxy. It uses RecaptchaV3TaskProxyless and CaptchaClient.solve(), returning a gRecaptchaResponse token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, pageAction, and the required minimum score from the target page. - STEP-03 - Create RecaptchaV3TaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a gRecaptchaResponse token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a reCAPTCHA v3 challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/tencent_proxy.py b/examples/sync/tencent_proxy.py index 48a6288..1314907 100644 --- a/examples/sync/tencent_proxy.py +++ b/examples/sync/tencent_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve Tencent captcha through your own proxy. - -What it does: - This example shows how to solve Tencent CAPTCHA through your own proxy. It uses TencentTask and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the Tencent parameters from the target page and provide your proxy settings. - STEP-03 - Create TencentTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Tencent captcha challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/tencent_proxyless.py b/examples/sync/tencent_proxyless.py index 1b0a3e7..fd620bc 100644 --- a/examples/sync/tencent_proxyless.py +++ b/examples/sync/tencent_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve Tencent captcha without a proxy. - -What it does: - This example shows how to solve Tencent CAPTCHA without a proxy. It uses TencentTaskProxyless and CaptchaClient.solve(), returning appid, ret, ticket, and randstr values. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, appId, and any non-default captchaScript from the target page. - STEP-03 - Create TencentTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print appid, ret, ticket, and randstr values. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Tencent captcha challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/turnstile_proxy.py b/examples/sync/turnstile_proxy.py index bd3d268..748f2e2 100644 --- a/examples/sync/turnstile_proxy.py +++ b/examples/sync/turnstile_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve Cloudflare turnstile through your own proxy. - -What it does: - This example shows how to solve Cloudflare Turnstile through your own proxy. It uses TurnstileTask and CaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract the Turnstile parameters from the target page and provide your proxy settings. - STEP-03 - Create TurnstileTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Cloudflare Turnstile challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/turnstile_proxyless.py b/examples/sync/turnstile_proxyless.py index c5719a7..2a32588 100644 --- a/examples/sync/turnstile_proxyless.py +++ b/examples/sync/turnstile_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve Cloudflare turnstile without a proxy. - -What it does: - This example shows how to solve Cloudflare Turnstile without a proxy. It uses TurnstileTaskProxyless and CaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL, websiteKey, and any Challenge-page action, data, and pagedata values from the target page. - STEP-03 - Create TurnstileTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Cloudflare Turnstile challenge. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/yandex_smartcaptcha_image.py b/examples/sync/yandex_smartcaptcha_image.py index be93a52..9973cdc 100644 --- a/examples/sync/yandex_smartcaptcha_image.py +++ b/examples/sync/yandex_smartcaptcha_image.py @@ -1,13 +1,4 @@ -"""Example: Solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. - -What it does: - This example shows how to solve an image-based Yandex SmartCaptcha from bundled local images without a proxy. It uses YandexSmartCaptchaImageTask and CaptchaClient.solve(), returning pixel coordinates to click. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The challenge and instruction images come from examples/assets. - STEP-03 - Create YandexSmartCaptchaImageTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print pixel coordinates to click. Applying the solution and verifying acceptance are target-specific. +"""Example: Solve an image-based Yandex SmartCaptcha. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/yandex_smartcaptcha_kaleidoscope.py b/examples/sync/yandex_smartcaptcha_kaleidoscope.py index 600b34f..694e2f9 100644 --- a/examples/sync/yandex_smartcaptcha_kaleidoscope.py +++ b/examples/sync/yandex_smartcaptcha_kaleidoscope.py @@ -1,13 +1,15 @@ -"""Example: Solve a Yandex smartcaptcha kaleidoscope puzzle from a bundled local image without a proxy. +"""Example: Solve an image-based Yandex SmartCaptcha Kaleidoscope puzzle. -What it does: - This example shows how to solve a Yandex SmartCaptcha Kaleidoscope puzzle from a bundled local image without a proxy. It uses YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve(), returning the number of slider-arrow clicks. +This example reads the bundled Kaleidoscope challenge image, encodes it as +Base64, sends it together with the puzzle-step sequence without a proxy, and +prints how many times to click the slider arrow. It uses +YandexSmartCaptchaKaleidoscopeTask and CaptchaClient.solve(). How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. The challenge image comes from examples/assets and the puzzle-step sequence is captured from the challenge. - STEP-03 - Create YandexSmartCaptchaKaleidoscopeTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print the number of slider-arrow clicks. Applying the solution and verifying acceptance are target-specific. +STEP-01 - Configure CaptchaClient and locate the bundled challenge image. +STEP-02 - Encode the image and create a task with the captured puzzle steps. +STEP-03 - Call solve(), which creates the task and polls for its solution. +STEP-04 - Print the slider-arrow click count, or report the error. Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/yandex_smartcaptcha_proxy.py b/examples/sync/yandex_smartcaptcha_proxy.py index 52bbeeb..08a2fc5 100644 --- a/examples/sync/yandex_smartcaptcha_proxy.py +++ b/examples/sync/yandex_smartcaptcha_proxy.py @@ -1,13 +1,5 @@ -"""Example: Solve token-based Yandex smartcaptcha through your own proxy. - -What it does: - This example shows how to solve token-based Yandex SmartCaptcha through your own proxy. It uses YandexSmartCaptchaTask and CaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page and provide your proxy settings. - STEP-03 - Create YandexSmartCaptchaTask and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Yandex SmartCaptcha challenge (token-based). Prerequisites: Set the CAPTCHA_API_KEY environment variable. diff --git a/examples/sync/yandex_smartcaptcha_proxyless.py b/examples/sync/yandex_smartcaptcha_proxyless.py index 87a979d..af1b089 100644 --- a/examples/sync/yandex_smartcaptcha_proxyless.py +++ b/examples/sync/yandex_smartcaptcha_proxyless.py @@ -1,13 +1,5 @@ -"""Example: Solve token-based Yandex smartcaptcha without a proxy. - -What it does: - This example shows how to solve token-based Yandex SmartCaptcha without a proxy. It uses YandexSmartCaptchaTaskProxyless and CaptchaClient.solve(), returning a token. - -How it works: - STEP-01 - Configure CaptchaClient with the API key. - STEP-02 - Obtain the task parameters. Extract websiteURL and websiteKey from the target page. - STEP-03 - Create YandexSmartCaptchaTaskProxyless and pass it to solver.solve(task), which creates and polls the task. - STEP-04 - Print a token. Applying the solution and verifying acceptance are target-specific. +""" +Example: Solve a Yandex SmartCaptcha challenge (token-based). Prerequisites: Set the CAPTCHA_API_KEY environment variable.