Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions twikit/_captcha/capsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,32 @@ class Capsolver(CaptchaSolver):
max_attempts : :class:`int`, default=3
The maximum number of attempts to solve the captcha.
get_result_interval : :class:`float`, default=1.0

use_blob_data : :class:`bool`, default=False
api_url : :class:`str`, default='https://api.capsolver.com'
Base URL for Capsolver API. Can be changed to use alternative API endpoints.
"""

def __init__(
self,
api_key: str,
max_attempts: int = 3,
get_result_interval: float = 1.0,
use_blob_data: bool = False
use_blob_data: bool = False,
api_url: str = 'https://api.capsolver.com'
) -> None:
self.api_key = api_key
self.get_result_interval = get_result_interval
self.max_attempts = max_attempts
self.use_blob_data = use_blob_data
self.api_url = api_url.rstrip('/')

def create_task(self, task_data: dict) -> dict:
data = {
'clientKey': self.api_key,
'task': task_data
}
response = httpx.post(
'https://api.capsolver.com/createTask',
f'{self.api_url}/createTask',
json=data,
headers={'content-type': 'application/json'}
).json()
Expand All @@ -65,7 +68,7 @@ def get_task_result(self, task_id: str) -> dict:
'taskId': task_id
}
response = httpx.post(
'https://api.capsolver.com/getTaskResult',
f'{self.api_url}/getTaskResult',
json=data,
headers={'content-type': 'application/json'}
).json()
Expand Down