ImageToText

To import this module:

from python3_capsolver.image_to_text import ImageToText
class python3_capsolver.image_to_text.ImageToText(captcha_type: ImageToTextTaskTypeEnm | str = ImageToTextTaskTypeEnm.ImageToTextTask, *args, **kwargs)

The class is used to work with Capsolver Image captcha solving methods.

Parameters:
  • api_key – Capsolver API key

  • captcha_type (ImageToTextTaskTypeEnm | str) – Captcha type name, like ImageToTextTask and etc.

Examples

>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> ImageToText(api_key="CAI-12345....").captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'gcphjd'}
                  )
>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> ImageToText(api_key="CAI-12345....",
...             module='queueit'
...            ).captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'zzzzz'}
                  )
>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> ImageToText(api_key="CAI-12345....",
...             module='dell',
...             score=0.98,
...             case=True,
...            ).captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'gcphjd'}
                  )
>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> with ImageToText(api_key="CAI-12345....") as image_to_text_inst:
...    image_to_text_inst.captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'gcphjd'}
                  )
>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> await ImageToText(api_key="CAI-12345....").aio_captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'gcphjd'}
                  )
>>> with open('some_image.jpeg', 'rb') as img_file:
...    img_data = img_file.read()
>>> body = base64.b64encode(img_data).decode("utf-8")
>>> with ImageToText(api_key="CAI-12345....") as image_to_text_inst:
...    await image_to_text_inst.aio_captcha_handler(body=body)
CaptchaResponseSer(errorId=0,
                   errorCode=None,
                   errorDescription=None,
                   taskId='73bdcd28-6c77-4414-8....',
                   status=<ResponseStatusEnm.Ready: 'ready'>,
                   solution={'confidence': 0.9585, 'text': 'gcphjd'}
                  )
Returns:

CaptchaResponseSer model with full server response

captcha_handler(body: str) CaptchaResponseSer

Synchronous method for captcha solving

Parameters:

body (str) – Base64 encoded content of the image, decoded into str

Returns:

CaptchaResponseSer model with full server response

Return type:

CaptchaResponseSer

Notes

Check class docstring for more info

async aio_captcha_handler(body: str) CaptchaResponseSer

Asynchronous method for captcha solving

Parameters:

body (str) – Base64 encoded content of the image, decoded into str

Returns:

CaptchaResponseSer model with full server response

Return type:

CaptchaResponseSer

Notes

Check class docstring for more info