From 0608d40e208e3275968cc289449a0a19d540a1e1 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 13 Nov 2023 10:17:58 +0300 Subject: [PATCH] Update result_handler.py --- src/python_rucaptcha/core/result_handler.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/python_rucaptcha/core/result_handler.py b/src/python_rucaptcha/core/result_handler.py index ca0892cb..1753fb9a 100644 --- a/src/python_rucaptcha/core/result_handler.py +++ b/src/python_rucaptcha/core/result_handler.py @@ -1,5 +1,4 @@ import time -import logging from typing import Union import aiohttp @@ -21,7 +20,6 @@ def get_sync_result(get_payload: GetTaskResultRequestSer, sleep_time: int, url_r captcha_response = GetTaskResultResponseSer( **requests.post(url_response, json=get_payload.dict()).json(), taskId=get_payload.taskId ) - logging.warning(f'{captcha_response = }') # if the captcha has not been resolved yet, wait if captcha_response.status == "processing": time.sleep(sleep_time) @@ -44,21 +42,17 @@ async def get_async_result( async with aiohttp.ClientSession() as session: for _ in attempts: try: - logging.warning(f"{get_payload = }") - logging.warning(f"{url_response = }") # send a request for the result of solving the captcha async with session.post(url_response, json=get_payload.model_dump(), raise_for_status=True) as resp: - logging.warning(f"{resp.status = }") captcha_response = await resp.json(content_type=None) - logging.warning(f"{captcha_response = }") captcha_response = GetTaskResultResponseSer(**captcha_response, taskId=get_payload.taskId) - logging.warning(f"{captcha_response = }") # if the captcha has not been resolved yet, wait if captcha_response.status == "processing": time.sleep(sleep_time) - else: + continue + elif captcha_response.errorId != 0: return captcha_response.model_dump() except Exception as error: - logging.warning(f"{error = }") return error + return captcha_response.model_dump()