1
- import requests
2
1
import logging
3
2
import time
4
3
4
+ import requests
5
+
5
6
logging .basicConfig (level = logging .INFO )
6
7
7
8
RECAPTCHAV2_TYPE = "RecaptchaV2TaskProxyless"
22
23
READY_STATUS = "ready"
23
24
FAILED_STATUS = "failed"
24
25
26
+
25
27
class TaskBadParametersError (Exception ):
26
28
pass
27
29
30
+
28
31
class ApiClient :
29
32
HOST = "https://api.nextcaptcha.com"
30
33
@@ -68,7 +71,8 @@ def _send(self, task: dict) -> dict:
68
71
if time .time () - start_time > TIMEOUT :
69
72
return {"errorId" : 12 , "errorDescription" : "Timeout" , "status" : "failed" }
70
73
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 })
72
76
if resp .status_code != 200 :
73
77
if self .open_log :
74
78
logging .error (f"Error: { resp .status_code } { resp .text } " )
@@ -84,12 +88,15 @@ def _send(self, task: dict) -> dict:
84
88
return resp .json ()
85
89
time .sleep (1 )
86
90
91
+
87
92
class NextCaptchaAPI :
88
93
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 } " )
90
96
self .api = ApiClient (client_key = client_key , solft_id = solft_id , callback_url = callback_url , open_log = open_log )
91
97
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 :
93
100
"""
94
101
Solve reCAPTCHA v2 challenge.
95
102
@@ -107,10 +114,12 @@ def recaptchav2(self, website_url: str, website_key: str, recaptcha_data_s_value
107
114
"recaptchaDataSValue" : recaptcha_data_s_value ,
108
115
"isInvisible" : is_invisible ,
109
116
"apiDomain" : api_domain ,
117
+ "pageAction" : page_action ,
110
118
}
111
119
return self .api ._send (task )
112
120
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 :
114
123
"""
115
124
Solve reCAPTCHA v2 Enterprise challenge.
116
125
@@ -128,10 +137,13 @@ def recaptchav2enterprise(self, website_url: str, website_key: str, enterprise_p
128
137
"enterprisePayload" : enterprise_payload ,
129
138
"isInvisible" : is_invisible ,
130
139
"apiDomain" : api_domain ,
140
+ "pageAction" : page_action ,
131
141
}
132
142
return self .api ._send (task )
133
143
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 :
135
147
"""
136
148
Solve reCAPTCHA v3 challenge.
137
149
@@ -179,7 +191,9 @@ def recaptcha_mobile(self, app_key: str, app_package_name: str = "", app_action:
179
191
}
180
192
return self .api ._send (task )
181
193
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 :
183
197
"""
184
198
Solve hCaptcha challenge.
185
199
@@ -210,7 +224,9 @@ def hcaptcha(self, website_url: str, website_key: str, is_invisible: bool = Fals
210
224
task ["proxyPassword" ] = proxy_password
211
225
return self .api ._send (task )
212
226
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 :
214
230
"""
215
231
Solve hCaptcha Enterprise challenge.
216
232
@@ -239,7 +255,9 @@ def hcaptcha_enterprise(self, website_url: str, website_key: str, enterprise_pay
239
255
}
240
256
return self .api ._send (task )
241
257
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 :
243
261
"""
244
262
Solve FunCaptcha challenge.
245
263
@@ -274,4 +292,4 @@ def get_balance(self) -> str:
274
292
275
293
:return: A string representing the account balance.
276
294
"""
277
- return self .api ._get_balance ()
295
+ return self .api ._get_balance ()
0 commit comments