From 014d5081e40703ad5726bc598bcdaaf21f2d6af2 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sat, 5 Oct 2024 21:11:39 +0300 Subject: [PATCH] Delete get_answer.py --- src/python3_anticaptcha/get_answer.py | 54 --------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/python3_anticaptcha/get_answer.py diff --git a/src/python3_anticaptcha/get_answer.py b/src/python3_anticaptcha/get_answer.py deleted file mode 100644 index 8ad17d8..0000000 --- a/src/python3_anticaptcha/get_answer.py +++ /dev/null @@ -1,54 +0,0 @@ -import time -import asyncio - -import aiohttp -import requests -from requests.adapters import HTTPAdapter - -from python3_anticaptcha.config import get_result_url, attempts_generator - - -def get_sync_result(result_payload: dict, sleep_time: int, **kwargs) -> dict: - # create a session - session = requests.Session() - # set the number of attempts to connect to the server in case of error - session.mount("http://", HTTPAdapter(max_retries=5)) - session.mount("https://", HTTPAdapter(max_retries=5)) - session.verify = False - - attempts = attempts_generator() - for _ in attempts: - captcha_response = session.post(get_result_url, json=result_payload, **kwargs).json() - - if captcha_response["errorId"] == 0: - if captcha_response["status"] == "processing": - time.sleep(sleep_time) - else: - captcha_response.update({"taskId": result_payload["taskId"]}) - session.close() - return captcha_response - else: - captcha_response.update({"taskId": result_payload["taskId"]}) - session.close() - return captcha_response - - -async def get_async_result(result_payload: dict, sleep_time: int) -> dict: - attempts = attempts_generator() - # Send request for status of captcha solution. - async with aiohttp.ClientSession() as session: - for _ in attempts: - async with session.post(get_result_url, json=result_payload) as resp: - json_result = await resp.json() - # if there is no error, check CAPTCHA status - if json_result["errorId"] == 0: - # If not yet resolved, wait - if json_result["status"] == "processing": - await asyncio.sleep(sleep_time) - # otherwise return response - else: - json_result.update({"taskId": result_payload["taskId"]}) - return json_result - else: - json_result.update({"taskId": result_payload["taskId"]}) - return json_result