python-rucaptcha icon indicating copy to clipboard operation
python-rucaptcha copied to clipboard

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

Open bshahin opened this issue 5 months ago • 2 comments

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.py — ServiceEnm.CAPTCHAAI.
  • core/serializer.py — urls_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.

bshahin avatar Jun 17 '26 07:06 bshahin

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!

bshahin101 avatar Jun 18 '26 08:06 bshahin101

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!

bshahin101 avatar Jun 18 '26 08:06 bshahin101