TemuCaptcha

To import this module:

from python_rucaptcha.temu_captcha import TemuCaptcha
class python_rucaptcha.temu_captcha.TemuCaptcha(save_format: str | SaveFormatsEnm = SaveFormatsEnm.TEMP, img_clearing: bool = True, img_path: str = 'PythonRuCaptchaImages', *args, **kwargs: dict[str, Any])
__init__(save_format: str | SaveFormatsEnm = SaveFormatsEnm.TEMP, img_clearing: bool = True, img_path: str = 'PythonRuCaptchaImages', *args, **kwargs: dict[str, Any])

Solve TemuImageTask CAPTCHA via 2Captcha/RuCaptcha API.

This class creates and monitors TemuImageTask jobs, which require a base64‐encoded background image plus an array of movable image pieces (parts) in base64 format. It extends BaseCaptcha to handle the low‐level request/response workflow.

Parameters:
  • save_format (str | SaveFormatsEnm) – Where to save temporary images. - SaveFormatsEnm.TEMP: use system temp directory - SaveFormatsEnm.CONST: keep files in img_path until deletion

  • img_clearing (bool) – If True and save_format is CONST, delete the img_path directory when this instance is destroyed.

  • img_path (str) – Directory under which to store downloaded or decoded images before sending to the API.

  • *args – Positional args forwarded to BaseCaptcha constructor (e.g. client_key, method override).

  • **kwargs (dict[str, Any]) – Keyword args forwarded to BaseCaptcha for task creation. Common params include: - redirectUri: URL to confirm CAPTCHA resolution - any other API‐supported parameters

Examples

>>> captcha = TemuCaptcha(rucaptcha_key="YOUR_API_KEY")
>>> response = captcha.captcha_handler(
...     parts=["part1_b64", "part2_b64", "part3_b64"],
...     captcha_base64=b"full_image_b64"
... )
>>> print(response)
{
    "errorId": 0,
    "status": "ready",
    "solution": {
        "coordinates": [{"x":155,"y":358}, {"x":152,"y":153}, {"x":251,"y":333}]
    },
    "cost": "0.0012",
    "createTime": 1754563182,
    "endTime": 1754563190,
    "taskId": 80306543329,
    "ip": "46.53.232.76",
    "solveCount": 1
}
captcha_handler(parts: list[str], captcha_link: str | None = None, captcha_file: str | None = None, captcha_base64: bytes | None = None, **kwargs: dict[str, Any]) dict[str, Any]

Synchronously solve a TemuImageTask.

Parameters:
  • parts (list[str]) – List of base64‐encoded strings for each movable image piece.

  • captcha_link (str | None) – URL to background image. Overrides captcha_file and captcha_base64 if provided.

  • captcha_file (str | None) – Path to an image file to read & send.

  • captcha_base64 (bytes | None) – Raw bytes or base64 string of the background image.

  • **kwargs (dict[str, Any]) – Passed through to the HTTP request call (e.g. timeout, headers).

Returns:

Full JSON response from the 2Captcha/RuCaptcha API,

including errorId, taskId, status, solution, cost, times, etc.

Return type:

dict[str, Any]

async aio_captcha_handler(parts: list[str], captcha_link: str | None = None, captcha_file: str | None = None, captcha_base64: bytes | None = None) dict[str, Any]

Asynchronously solve a TemuImageTask.

Parameters:
  • parts (list[str]) – List of base64‐encoded strings for each movable image piece.

  • captcha_link (str | None) – URL to background image.

  • captcha_file (str | None) – Path to an image file to read & send.

  • captcha_base64 (bytes | None) – Raw bytes or base64 string of image.

  • **kwargs – Passed through to the async HTTP request call.

Returns:

API response containing task status and solution.

Return type:

dict[str, Any]