Yandex SmartCaptcha

To import this module:

from python_rucaptcha.yandex_smart_captcha import YandexSmartCaptcha
class python_rucaptcha.yandex_smart_captcha.YandexSmartCaptcha(websiteURL: str | None = None, websiteKey: str | None = None, method: str | YandexSmartCaptchaEnm | CoordinatesCaptchaEnm = YandexSmartCaptchaEnm.YandexSmartCaptchaTaskProxyless, userAgent: str | None = None, cookies: str | None = None, proxyType: str | None = None, proxyAddress: str | None = None, proxyPort: int | None = None, proxyLogin: str | None = None, proxyPassword: str | None = None, imgType: str | None = None, comment: str | None = None, save_format: str | SaveFormatsEnm = SaveFormatsEnm.TEMP, img_clearing: bool = True, img_path: str = 'PythonRuCaptchaYandexSmart', *args, **kwargs)

The class is used to work with Yandex SmartCaptcha.

Supports three 2Captcha task types:
  • YandexSmartCaptchaTaskProxyless (token, no proxy)

  • YandexSmartCaptchaTask (token, user proxy)

  • CoordinatesTask (image, two imgType modes: smart_captcha, pazl_smart_captcha)

Parameters:
  • rucaptcha_key – User API key

  • websiteURL (str | None) – Full URL of the page where the captcha is loaded (token methods)

  • websiteKey (str | None) – Sitekey from the page source (token methods)

  • method (str | YandexSmartCaptchaEnm | CoordinatesCaptchaEnm) – Captcha type. Default YandexSmartCaptchaTaskProxyless.

  • userAgent (str | None) – Browser User-Agent to use (token methods, optional)

  • cookies (str | None) – Cookies to send in the request (token methods, optional, format “name1=value1;name2=value2”)

  • proxyType (str | None) – Proxy type (http, https, socks4, socks5) - required for YandexSmartCaptchaTask

  • proxyAddress (str | None) – Proxy IP/hostname - required for YandexSmartCaptchaTask

  • proxyPort (int | None) – Proxy port - required for YandexSmartCaptchaTask

  • proxyLogin (str | None) – Proxy login (optional)

  • proxyPassword (str | None) – Proxy password (optional)

  • imgType (str | None) – Image variant type - “smart_captcha” or “pazl_smart_captcha” (CoordinatesTask only)

  • comment (str | None) – Text hint for the worker - required for imgType=”smart_captcha”

  • save_format (str | SaveFormatsEnm) – How to save the image - “temp” or “const” (CoordinatesTask only)

  • img_clearing (bool) – Whether to delete the image folder on instance destruction

  • img_path (str) – Folder name for saved images

Examples

>>> YandexSmartCaptcha(
...     rucaptcha_key="aa9011f31111181111168611f1151122",
...     websiteURL="https://example.com/",
...     websiteKey="Y5Lh0ti...",
... ).captcha_handler()
{"errorId": 0, "status": "ready", "solution": {"token": "..."}, "taskId": ...}
>>> await YandexSmartCaptcha(
...     rucaptcha_key="aa9011f31111181111168611f1151122",
...     websiteURL="https://example.com/",
...     websiteKey="Y5Lh0ti...",
...     method=YandexSmartCaptchaEnm.YandexSmartCaptchaTask,
...     proxyType="http",
...     proxyAddress="1.2.3.4",
...     proxyPort=8080,
... ).aio_captcha_handler()
{"errorId": 0, "status": "ready", "solution": {"token": "..."}, "taskId": ...}
>>> YandexSmartCaptcha(
...     rucaptcha_key="aa9011f31111181111168611f1151122",
...     method=CoordinatesCaptchaEnm.CoordinatesTask,
...     imgType="smart_captcha",
...     comment="select objects in the order of the instruction",
... ).captcha_handler(
...     captcha_file="src/examples/088636.png",
...     imgInstructions_file="src/examples/bounding_box_start.png",
... )
{"errorId": 0, "status": "ready", "solution": {"coordinates": [{"x": 57, "y": 82}, ...]}, "taskId": ...}
captcha_handler(captcha_link: str | None = None, captcha_file: str | None = None, captcha_base64: bytes | None = None, imgInstructions_link: str | None = None, imgInstructions_file: str | None = None, imgInstructions_base64: bytes | None = None, **kwargs: dict[str, Any]) dict[str, Any]

Sync solving method.

async aio_captcha_handler(captcha_link: str | None = None, captcha_file: str | None = None, captcha_base64: bytes | None = None, imgInstructions_link: str | None = None, imgInstructions_file: str | None = None, imgInstructions_base64: bytes | None = None, **kwargs: dict[str, Any]) dict[str, Any]

Async solving method.