Skip to content

Add CaptchaAI as a provider (classic in.php/res.php adapter)#367

Open
bshahin wants to merge 2 commits into
AndreiDrang:masterfrom
bshahin:add-captchaai-provider
Open

Add CaptchaAI as a provider (classic in.php/res.php adapter)#367
bshahin wants to merge 2 commits into
AndreiDrang:masterfrom
bshahin:add-captchaai-provider

Conversation

@bshahin

@bshahin bshahin commented Jun 17, 2026

Copy link
Copy Markdown

Add CaptchaAI as a provider

Per #366. Adds CaptchaAI as a selectable service.

CaptchaAI is 2Captcha-API-compatible, but via the classic in.php/res.php form-parameter API rather than the JSON createTask API the library uses for the other services. So this PR keeps the public classes unchanged and adds a small adapter that translates the library's task payload into classic params, submits, polls, and returns the usual GetTaskResultResponseSer shape.

Changes

  • core/enums.pyServiceEnm.CAPTCHAAI.
  • core/serializer.pyurls_set() routes CaptchaAI to https://ocr.captchaai.com/in.php / res.php.
  • core/captchaai.py (new) — classic-API adapter (sync solve + async aio_solve): maps the createTask payload → classic params, parses OK|… / CAPCHA_NOT_READY / ERROR_*.
  • core/base.py — routes sync/async processing to the adapter when service_type == CAPTCHAAI.
  • README.md — usage note.
  • tests/test_captchaai.py — no-network unit tests.

Usage

from python_rucaptcha.turnstile import Turnstile
from python_rucaptcha.core.enums import ServiceEnm

result = Turnstile(
    rucaptcha_key="CAPTCHAAI_KEY",
    service_type=ServiceEnm.CAPTCHAAI,
    websiteURL="https://example.com",
    websiteKey="0x4AAAAAAA...",
    userAgent="Mozilla/5.0 ...",
).captcha_handler()

Supported task types

Turnstile, reCAPTCHA v2 (incl. Enterprise), reCAPTCHA v3, ImageToText. Other types raise a clear ValueError so callers fail fast.

Testing

  • tests/test_captchaai.py (9 unit tests, no network) — enum, URL routing, and all param mappings pass.
  • Verified live end-to-end: a reCAPTCHA v2 solve through ServiceEnm.CAPTCHAAI returns a valid token.

Happy to adjust naming/structure to match your preferences, and to extend the type coverage.

CaptchaAI is 2Captcha-API-compatible via the classic in.php/res.php endpoints
(rather than the JSON createTask API). Adds ServiceEnm.CAPTCHAAI, URL routing in
CaptchaOptionsSer.urls_set(), and a small classic-API adapter (core/captchaai.py)
that maps the library's createTask payloads to classic params and parses the
classic responses, returning the usual GetTaskResultResponseSer shape so the
public Turnstile / ReCaptcha / ImageCaptcha classes work transparently.

Supported task types: Turnstile, reCAPTCHA v2 (incl. Enterprise), reCAPTCHA v3,
ImageToText; unsupported types raise a clear ValueError. Adds README usage note
and tests/test_captchaai.py (no-network unit tests).

Refs AndreiDrang#366
@bshahin101

Copy link
Copy Markdown

Quick note on the red CI: the failing test (3.11) job is the live suite running without RUCAPTCHA_KEY (GitHub doesn't expose the repo secret to fork PRs), so those failures are the environment, not the change — the tests I added tests/test_captchaai.py) are network-free and pass. Happy to adjust anything when you get a chance to review. Thanks!

1 similar comment
@bshahin101

Copy link
Copy Markdown

Quick note on the red CI: the failing test (3.11) job is the live suite running without RUCAPTCHA_KEY (GitHub doesn't expose the repo secret to fork PRs), so those failures are the environment, not the change — the tests I added tests/test_captchaai.py) are network-free and pass. Happy to adjust anything when you get a chance to review. Thanks!

…iohttp + ValueError)

Addresses Codacy broad-exception-caught flags on the CaptchaAI adapter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants