Skip to content

Commit

Permalink
recaptcha v2 add pageAction
Browse files Browse the repository at this point in the history
  • Loading branch information
nextcaptcha committed Mar 27, 2024
1 parent 772ddbc commit 74d9172
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nextcaptcha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@



__version__ = '1.0.0'
__version__ = '1.0.1'
38 changes: 28 additions & 10 deletions nextcaptcha/next.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests
import logging
import time

import requests

logging.basicConfig(level=logging.INFO)

RECAPTCHAV2_TYPE = "RecaptchaV2TaskProxyless"
Expand All @@ -22,9 +23,11 @@
READY_STATUS = "ready"
FAILED_STATUS = "failed"


class TaskBadParametersError(Exception):
pass


class ApiClient:
HOST = "https://api.nextcaptcha.com"

Expand Down Expand Up @@ -68,7 +71,8 @@ def _send(self, task: dict) -> dict:
if time.time() - start_time > TIMEOUT:
return {"errorId": 12, "errorDescription": "Timeout", "status": "failed"}

resp = self.session.post(url=self.HOST + "/getTaskResult", json={"clientKey": self.client_key, "taskId": task_id})
resp = self.session.post(url=self.HOST + "/getTaskResult",
json={"clientKey": self.client_key, "taskId": task_id})
if resp.status_code != 200:
if self.open_log:
logging.error(f"Error: {resp.status_code} {resp.text}")
Expand All @@ -84,12 +88,15 @@ def _send(self, task: dict) -> dict:
return resp.json()
time.sleep(1)


class NextCaptchaAPI:
def __init__(self, client_key: str, solft_id: str = "", callback_url: str = "", open_log: bool = True) -> None:
logging.info(f"NextCaptchaAPI created with clientKey={client_key} solftId={solft_id} callbackUrl={callback_url}")
logging.info(
f"NextCaptchaAPI created with clientKey={client_key} solftId={solft_id} callbackUrl={callback_url}")
self.api = ApiClient(client_key=client_key, solft_id=solft_id, callback_url=callback_url, open_log=open_log)

def recaptchav2(self, website_url: str, website_key: str, recaptcha_data_s_value: str = "", is_invisible: bool = False, api_domain: str = "") -> dict:
def recaptchav2(self, website_url: str, website_key: str, recaptcha_data_s_value: str = "",
is_invisible: bool = False, api_domain: str = "", page_action: str = "") -> dict:
"""
Solve reCAPTCHA v2 challenge.
Expand All @@ -107,10 +114,12 @@ def recaptchav2(self, website_url: str, website_key: str, recaptcha_data_s_value
"recaptchaDataSValue": recaptcha_data_s_value,
"isInvisible": is_invisible,
"apiDomain": api_domain,
"pageAction": page_action,
}
return self.api._send(task)

def recaptchav2enterprise(self, website_url: str, website_key: str, enterprise_payload: dict = {}, is_invisible: bool = False, api_domain: str = "") -> dict:
def recaptchav2enterprise(self, website_url: str, website_key: str, enterprise_payload: dict = {},
is_invisible: bool = False, api_domain: str = "", page_action: str = "") -> dict:
"""
Solve reCAPTCHA v2 Enterprise challenge.
Expand All @@ -128,10 +137,13 @@ def recaptchav2enterprise(self, website_url: str, website_key: str, enterprise_p
"enterprisePayload": enterprise_payload,
"isInvisible": is_invisible,
"apiDomain": api_domain,
"pageAction": page_action,
}
return self.api._send(task)

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:
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:
"""
Solve reCAPTCHA v3 challenge.
Expand Down Expand Up @@ -179,7 +191,9 @@ def recaptcha_mobile(self, app_key: str, app_package_name: str = "", app_action:
}
return self.api._send(task)

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:
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:
"""
Solve hCaptcha challenge.
Expand Down Expand Up @@ -210,7 +224,9 @@ def hcaptcha(self, website_url: str, website_key: str, is_invisible: bool = Fals
task["proxyPassword"] = proxy_password
return self.api._send(task)

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:
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:
"""
Solve hCaptcha Enterprise challenge.
Expand Down Expand Up @@ -239,7 +255,9 @@ def hcaptcha_enterprise(self, website_url: str, website_key: str, enterprise_pay
}
return self.api._send(task)

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:
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:
"""
Solve FunCaptcha challenge.
Expand Down Expand Up @@ -274,4 +292,4 @@ def get_balance(self) -> str:
:return: A string representing the account balance.
"""
return self.api._get_balance()
return self.api._get_balance()

0 comments on commit 74d9172

Please sign in to comment.