Skip to content

Commit

Permalink
Update result_handler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Nov 13, 2023
1 parent d9f425b commit 0608d40
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/python_rucaptcha/core/result_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import logging
from typing import Union

import aiohttp
Expand All @@ -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)
Expand All @@ -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()

0 comments on commit 0608d40

Please sign in to comment.