1- import requests
21import logging
32import time
43
4+ import requests
5+
56logging .basicConfig (level = logging .INFO )
67
78RECAPTCHAV2_TYPE = "RecaptchaV2TaskProxyless"
2223READY_STATUS = "ready"
2324FAILED_STATUS = "failed"
2425
26+
2527class TaskBadParametersError (Exception ):
2628 pass
2729
30+
2831class ApiClient :
2932 HOST = "https://api.nextcaptcha.com"
3033
@@ -68,7 +71,8 @@ def _send(self, task: dict) -> dict:
6871 if time .time () - start_time > TIMEOUT :
6972 return {"errorId" : 12 , "errorDescription" : "Timeout" , "status" : "failed" }
7073
71- resp = self .session .post (url = self .HOST + "/getTaskResult" , json = {"clientKey" : self .client_key , "taskId" : task_id })
74+ resp = self .session .post (url = self .HOST + "/getTaskResult" ,
75+ json = {"clientKey" : self .client_key , "taskId" : task_id })
7276 if resp .status_code != 200 :
7377 if self .open_log :
7478 logging .error (f"Error: { resp .status_code } { resp .text } " )
@@ -84,12 +88,15 @@ def _send(self, task: dict) -> dict:
8488 return resp .json ()
8589 time .sleep (1 )
8690
91+
8792class NextCaptchaAPI :
8893 def __init__ (self , client_key : str , solft_id : str = "" , callback_url : str = "" , open_log : bool = True ) -> None :
89- logging .info (f"NextCaptchaAPI created with clientKey={ client_key } solftId={ solft_id } callbackUrl={ callback_url } " )
94+ logging .info (
95+ f"NextCaptchaAPI created with clientKey={ client_key } solftId={ solft_id } callbackUrl={ callback_url } " )
9096 self .api = ApiClient (client_key = client_key , solft_id = solft_id , callback_url = callback_url , open_log = open_log )
9197
92- def recaptchav2 (self , website_url : str , website_key : str , recaptcha_data_s_value : str = "" , is_invisible : bool = False , api_domain : str = "" ) -> dict :
98+ def recaptchav2 (self , website_url : str , website_key : str , recaptcha_data_s_value : str = "" ,
99+ is_invisible : bool = False , api_domain : str = "" , page_action : str = "" ) -> dict :
93100 """
94101 Solve reCAPTCHA v2 challenge.
95102
@@ -107,10 +114,12 @@ def recaptchav2(self, website_url: str, website_key: str, recaptcha_data_s_value
107114 "recaptchaDataSValue" : recaptcha_data_s_value ,
108115 "isInvisible" : is_invisible ,
109116 "apiDomain" : api_domain ,
117+ "pageAction" : page_action ,
110118 }
111119 return self .api ._send (task )
112120
113- def recaptchav2enterprise (self , website_url : str , website_key : str , enterprise_payload : dict = {}, is_invisible : bool = False , api_domain : str = "" ) -> dict :
121+ def recaptchav2enterprise (self , website_url : str , website_key : str , enterprise_payload : dict = {},
122+ is_invisible : bool = False , api_domain : str = "" , page_action : str = "" ) -> dict :
114123 """
115124 Solve reCAPTCHA v2 Enterprise challenge.
116125
@@ -128,10 +137,13 @@ def recaptchav2enterprise(self, website_url: str, website_key: str, enterprise_p
128137 "enterprisePayload" : enterprise_payload ,
129138 "isInvisible" : is_invisible ,
130139 "apiDomain" : api_domain ,
140+ "pageAction" : page_action ,
131141 }
132142 return self .api ._send (task )
133143
134- def recaptchav3 (self , website_url : str , website_key : str , page_action : str = "" , api_domain : str = "" , proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" , proxy_password : str = "" ) -> dict :
144+ def recaptchav3 (self , website_url : str , website_key : str , page_action : str = "" , api_domain : str = "" ,
145+ proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" ,
146+ proxy_password : str = "" ) -> dict :
135147 """
136148 Solve reCAPTCHA v3 challenge.
137149
@@ -179,7 +191,9 @@ def recaptcha_mobile(self, app_key: str, app_package_name: str = "", app_action:
179191 }
180192 return self .api ._send (task )
181193
182- def hcaptcha (self , website_url : str , website_key : str , is_invisible : bool = False , enterprise_payload : dict = {}, proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" , proxy_password : str = "" ) -> dict :
194+ def hcaptcha (self , website_url : str , website_key : str , is_invisible : bool = False , enterprise_payload : dict = {},
195+ proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" ,
196+ proxy_password : str = "" ) -> dict :
183197 """
184198 Solve hCaptcha challenge.
185199
@@ -210,7 +224,9 @@ def hcaptcha(self, website_url: str, website_key: str, is_invisible: bool = Fals
210224 task ["proxyPassword" ] = proxy_password
211225 return self .api ._send (task )
212226
213- def hcaptcha_enterprise (self , website_url : str , website_key : str , enterprise_payload : dict = {}, is_invisible : bool = False , proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" , proxy_password : str = "" ) -> dict :
227+ def hcaptcha_enterprise (self , website_url : str , website_key : str , enterprise_payload : dict = {},
228+ is_invisible : bool = False , proxy_type : str = "" , proxy_address : str = "" ,
229+ proxy_port : int = 0 , proxy_login : str = "" , proxy_password : str = "" ) -> dict :
214230 """
215231 Solve hCaptcha Enterprise challenge.
216232
@@ -239,7 +255,9 @@ def hcaptcha_enterprise(self, website_url: str, website_key: str, enterprise_pay
239255 }
240256 return self .api ._send (task )
241257
242- def funcaptcha (self , website_public_key : str , website_url : str = "" , data : str = "" , proxy_type : str = "" , proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" , proxy_password : str = "" ) -> dict :
258+ def funcaptcha (self , website_public_key : str , website_url : str = "" , data : str = "" , proxy_type : str = "" ,
259+ proxy_address : str = "" , proxy_port : int = 0 , proxy_login : str = "" ,
260+ proxy_password : str = "" ) -> dict :
243261 """
244262 Solve FunCaptcha challenge.
245263
@@ -274,4 +292,4 @@ def get_balance(self) -> str:
274292
275293 :return: A string representing the account balance.
276294 """
277- return self .api ._get_balance ()
295+ return self .api ._get_balance ()
0 commit comments