@@ -10,6 +10,8 @@ class Capmonster:
1010 _CREATE_TASK_URL = "/createTask"
1111 _TASK_RESULT_URL = "/getTaskResult"
1212 _BALANCE_URL = "/getBalance"
13+ _INCORRECT_IMAGE_CAPTCHA_URL = "/reportIncorrectImageCaptcha"
14+ _INCORRECT_TOKEN_CAPTCHA_URL = "/reportIncorrectTokenCaptcha"
1315
1416 def __init__ (self , client_key ):
1517 self ._client_key = client_key
@@ -38,7 +40,8 @@ def join_task_result(self, task_id: int, maximum_time: int = 120):
3840 elif result is False :
3941 i += 1
4042 sleep (2 )
41- raise CapmonsterException (61 , "ERROR_MAXIMUM_TIME_EXCEED" , "Maximum time is exceed." )
43+ raise CapmonsterException (
44+ 61 , "ERROR_MAXIMUM_TIME_EXCEED" , "Maximum time is exceed." )
4245
4346 async def join_task_result_async (self , task_id : int , maximum_time : int = 120 ):
4447 for i in range (0 , maximum_time + 1 , 2 ):
@@ -48,7 +51,31 @@ async def join_task_result_async(self, task_id: int, maximum_time: int = 120):
4851 elif result is False :
4952 i += 1
5053 await asyncio .sleep (2 )
51- raise CapmonsterException (61 , "ERROR_MAXIMUM_TIME_EXCEED" , "Maximum time is exceed." )
54+ raise CapmonsterException (
55+ 61 , "ERROR_MAXIMUM_TIME_EXCEED" , "Maximum time is exceed." )
56+
57+ def report_incorrect_captcha (self , captcha_type : str , task_id : int ) -> bool :
58+ if captcha_type is not "image" or "token" :
59+ raise CapmonsterException (
60+ 1 , "ERROR_INCORRECT_CAPTCHA_TYPE" , "Valid captcha_type parameters are only 'image' or 'token'." )
61+ try :
62+ self ._report_incorrect_captcha (
63+ captcha_type = captcha_type , task_id = task_id )
64+ return True
65+ except :
66+ return False
67+
68+ @check_response ()
69+ def _report_incorrect_captcha (self , captcha_type : str , task_id : int ):
70+ data = {
71+ "clientKey" : self ._client_key ,
72+ "taskId" : task_id
73+ }
74+ if captcha_type is "image" :
75+ response = self ._make_request ("reportIncorrectImageCaptcha" , data )
76+ else :
77+ response = self ._make_request ("reportIncorrectTokenCaptcha" , data )
78+ return response
5279
5380 @staticmethod
5481 def _is_ready (response : dict ):
@@ -68,8 +95,13 @@ def _make_request(self, method: str, data: dict):
6895 elif method == "createTask" :
6996 _method = self ._CREATE_TASK_URL
7097 data ["softId" ] = self .__SOFT_ID
98+ elif method == "reportIncorrectImageCaptcha" :
99+ _method = self ._INCORRECT_IMAGE_CAPTCHA_URL
100+ elif method == "reportIncorrectTokenCaptcha" :
101+ _method = self ._INCORRECT_TOKEN_CAPTCHA_URL
71102 try :
72- response = requests .post ("{}{}" .format (self ._HOST_URL , _method ), json = data ).json ()
103+ response = requests .post ("{}{}" .format (
104+ self ._HOST_URL , _method ), json = data ).json ()
73105 except Exception as err :
74106 raise CapmonsterException (- 1 , type (err ).__name__ , str (err ))
75107 return response
@@ -88,7 +120,8 @@ def _add_cookies(cookies, data):
88120 elif type (cookies ) == list :
89121 for i in cookies :
90122 if not len (cookies ) % 2 == 0 :
91- raise AttributeError ("List cookies length must be even numbers" )
123+ raise AttributeError (
124+ "List cookies length must be even numbers" )
92125 if cookies .index (i ) % 2 == 0 :
93126 str_cookies += "{}=" .format (i )
94127 elif cookies [cookies .index (i )] == cookies [- 1 ]:
0 commit comments