@@ -24,6 +24,7 @@ def __init__(self, captcha_params: "CaptchaParams"):
2424 super ().__init__ ()
2525 self .captcha_params = captcha_params
2626 self .created_task_data = CaptchaResponseSer
27+
2728 # prepare session
2829 self .session = requests .Session ()
2930 self .session .mount ("http://" , HTTPAdapter (max_retries = RETRIES ))
@@ -37,6 +38,8 @@ def processing_captcha(self) -> dict:
3738
3839 # if task created and ready - return result
3940 if self .created_task_data .errorId == 0 :
41+ if str (self .created_task_data .status ).lower () == ResponseStatusEnm .Ready .value :
42+ return self .created_task_data .to_dict ()
4043 return self .__get_result ().to_dict ()
4144 else :
4245 self .created_task_data .status = ResponseStatusEnm .Failed
@@ -78,7 +81,10 @@ def __get_result(self, url_postfix: str = EndpointPostfixEnm.GET_TASK_RESULT.val
7881 )
7982 if resp .status_code in VALID_STATUS_CODES :
8083 result_data = CaptchaResponseSer (** resp .json ())
81- if result_data .status in (ResponseStatusEnm .Ready , ResponseStatusEnm .Failed ):
84+ if result_data .status in (
85+ ResponseStatusEnm .Ready ,
86+ ResponseStatusEnm .Failed ,
87+ ):
8288 # if captcha ready\failed or have unknown status - return exist data
8389 return result_data
8490 else :
@@ -89,12 +95,14 @@ def __get_result(self, url_postfix: str = EndpointPostfixEnm.GET_TASK_RESULT.val
8995
9096 # if captcha just created or in processing now - wait
9197 time .sleep (self .captcha_params .sleep_time )
98+
9299 # default response if server is silent
93100 self .result .errorId = 1
94101 self .result .errorCode = self .CAPTCHA_UNSOLVABLE
95102 self .result .errorDescription = self .CAPTCHA_UNSOLVABLE_DESCRIPTION
96103 self .result .taskId = self .created_task_data .taskId
97104 self .result .status = ResponseStatusEnm .Failed
105+ return self .result
98106
99107 @staticmethod
100108 def send_post_request (
0 commit comments