Skip to content
Merged
Show file tree
Hide file tree
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
87 changes: 82 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async def main():
# Send task and receive token
result = await client.solve_captcha(request)
print("reCAPTCHA Token:", result.get("gRecaptchaResponse"))
print("Cost:", result.get("cost")) # price of this solution in USD

if __name__ == "__main__":
asyncio.run(main())
Expand Down Expand Up @@ -144,6 +145,49 @@ if __name__ == "__main__":
asyncio.run(run_scraper())
```

### 3. Check your balance

`get_balance()` returns the raw `getBalance` API response, including your current balance in USD:

```python
async def main():
balance = await client.get_balance()
print("Balance:", balance.get("balance"))

if __name__ == "__main__":
asyncio.run(main())
```

---

## 🔧 Client Configuration

`ClientOptions` controls how the client connects to the CapMonster Cloud API:

| Option | Default | Description |
| :--- | :--- | :--- |
| `api_key` | — | **Required.** Your CapMonster Cloud API key from the [Dashboard](https://dash.capmonster.cloud/?utm_source=github&utm_medium=referral&utm_campaign=python_repo_readme). |
| `service_url` | `https://api.capmonster.cloud` | CapMonster Cloud API endpoint. |
| `client_timeout` | `20.0` | Timeout in seconds for a single HTTP request to the API. |
| `default_soft_id` | `55` | `softId` sent with every created task; identifies your software in the Dashboard. |
| `client_proxy` | `None` | Proxy for the connection to the CapMonster Cloud API itself: `ClientProxyInfo` with `proxyType` (`http` or `https`), `proxyAddress`, `proxyPort` and optional `proxyLogin` / `proxyPassword`. To route a solved task through a proxy, set `proxy` on the request object instead. |

```python
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import ClientProxyInfo

options = ClientOptions(
api_key="YOUR_CAPMONSTER_API_KEY",
client_timeout=30.0,
client_proxy=ClientProxyInfo(
proxyType="http",
proxyAddress="127.0.0.1",
proxyPort=8080,
),
)
client = CapMonsterClient(options=options)
```

---

## 🔄 Migrating from 2Captcha or Capsolver
Expand Down Expand Up @@ -217,15 +261,18 @@ All task types follow the official [CapMonster Cloud API documentation](https://
| :--- | :--- | :---: |
| **Cloudflare Turnstile** | `TurnstileRequest` | ✅ Supported |
| **reCAPTCHA v2** | `RecaptchaV2Request` | ✅ Supported |
| **reCAPTCHA v2 Enterprise** | `RecaptchaV2EnterpriseRequest` (optional `minScore`, 0.1–0.9) | ✅ Supported |
| **reCAPTCHA v3** | `RecaptchaV3ProxylessRequest` | ✅ Supported |
| **reCAPTCHA Enterprise** | `RecaptchaV2EnterpriseProxylessRequest` / `RecaptchaV2EnterpriseRequest` | ✅ Supported |
| **GeeTest (v3, v4)** | `GeeTestProxylessRequest` / `GeeTestRequest` | ✅ Supported |
| **reCAPTCHA v3 Enterprise** | `RecaptchaV3EnterpriseRequest` | ✅ Supported |
| **GeeTest (v3, v4)** | `GeetestRequest` | ✅ Supported |
| **FunCaptcha** | `FuncaptchaRequest` | ✅ Supported |
| **Amazon WAF** | `AmazonWafRequest` | ✅ Supported |
| **DataDome** | `DataDomeCustomTaskRequest` | 🌐 Proxy Required |
| **Imperva / Incapsula** | `ImpervaCustomTaskRequest` / `ImpervaCustomTaskProxylessRequest` | ✅ Supported |
| **Binance CAPTCHA** | `BinanceTaskRequest` / `BinanceTaskProxylessRequest` | ✅ Supported |
| **Imperva / Incapsula** | `ImpervaCustomTaskRequest` | ✅ Supported |
| **Binance CAPTCHA** | `BinanceTaskRequest` | ✅ Supported |
| **Standard Text CAPTCHA** | `ImageToTextRequest` | ✅ Supported |
| **Complex Image Tasks** | `RecaptchaComplexImageTaskRequest` | ✅ Supported |
| **Complex Image Tasks** | `RecaptchaComplexImageTaskRequest`, `RecognitionComplexImageTaskRequest`, `FunCaptchaComplexImageTaskRequest` | ✅ Supported |
| **Custom anti-bot tasks** | `TspdCustomTaskRequest`, `HuntCustomTaskRequest`, `FriendlyCustomTaskRequest`, `TenDiCustomTaskRequest`, `BasiliskCustomTaskRequest`, `AlibabaCustomTaskRequest`, `AltchaCustomTaskRequest`, `MTCaptchaRequest`, `YidunRequest`, `ProsopoTaskRequest` | ✅ Supported |

---

Expand All @@ -249,6 +296,36 @@ All task types follow the official [CapMonster Cloud API documentation](https://

---

## 🐞 Error Handling

Failed calls raise exceptions from `capmonstercloudclient.exceptions` (all subclass `BaseError`):

| Exception | Raised when |
| :--- | :--- |
| `GetTaskError` | `createTask` returned an API error (`errorId != 0`): zero balance, invalid task, and similar. |
| `GetResultError` | `getTaskResult` returned an API error while polling. |
| `GetBalanceError` | `get_balance()` returned an API error. |
| `UnknownRequestInstanceError` | `solve_captcha()` received an object that is not a supported request class. |
| `UnsupportedProxyTypeError` | `client_proxy` uses a protocol other than `http` / `https`. |
| `TimeoutError` (builtin) | No solution arrived within the maximum waiting time for that captcha type. |
| `HTTPException` (`http.client`) | The API answered with a non-200 HTTP status. |
| `TaskNotDefinedError`, `NumbersImagesErrors`, `ZeroImagesErrors`, `ExtraParamsError`, `UserAgentNotDefinedError` | Request validation failed (mostly complex image tasks): wrong number of images, missing task parameters or `userAgent`, and similar. |

```python
from capmonstercloudclient.exceptions import GetTaskError, GetResultError

try:
solution = await client.solve_captcha(request)
except GetTaskError as e:
print("Task rejected:", e) # e.g. ERROR_ZERO_BALANCE
except TimeoutError as e:
print("No solution in time:", e)
```

**Polling and timeouts.** The client polls `getTaskResult` automatically. Each captcha type has its own polling settings (delay before the first request, polling interval, maximum waiting time) — for example up to 180 seconds for reCAPTCHA tasks and 10 seconds for image-to-text tasks. When the time is up, `solve_captcha()` raises `TimeoutError`. When a task is solved, the returned dictionary also contains `cost` — the price of this solution in USD. Unsolved tasks are not charged.

---

## ⚙️ Best Practices

- **Use tokens promptly:** CAPTCHA tokens expire quickly (a reCAPTCHA v2 token is valid for 60 seconds after solving), so submit or inject the solution immediately after receiving the response.
Expand Down
13 changes: 1 addition & 12 deletions capmonstercloud_client/CapMonsterCloudClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
((RecaptchaV3EnterpriseRequest,), getRecaptchaV3Timeouts),
((ImageToTextRequest,), getImage2TextTimeouts),
((FuncaptchaRequest,), getFuncaptchaTimeouts),
((HcaptchaRequest,), getHcaptchaTimeouts),
((GeetestRequest,), getGeetestTimeouts),
((TurnstileRequest,), getTurnstileTimeouts),
((RecaptchaComplexImageTaskRequest, HcaptchaComplexImageTaskRequest,
((RecaptchaComplexImageTaskRequest,
FunCaptchaComplexImageTaskRequest), getImage2TextTimeouts),
((DataDomeCustomTaskRequest,), getDatadomeTimeouts),
((TenDiCustomTaskRequest,), getTenDiTimeouts),
Expand All @@ -34,10 +33,8 @@
((RecognitionComplexImageTaskRequest,), getCITTimeouts),
((MTCaptchaRequest,), getMTCaptchaTimeouts),
((YidunRequest,), getYidunTimeouts),
((TemuCustomTaskRequest,), getTemuTimeouts),
((ProsopoTaskRequest,), getProsopoTimeouts),
((AltchaCustomTaskRequest,), getAltchaTimeouts),
((CastleCustomTaskRequest,), getCastleTimeouts),
((TspdCustomTaskRequest,), getTspdTimeouts),
((HuntCustomTaskRequest,), getHuntTimeouts),
((AlibabaCustomTaskRequest,), getAlibabaTimeouts),
Expand Down Expand Up @@ -94,8 +91,6 @@ async def solve_captcha(self, request: Union[
ImageToTextRequest,
FuncaptchaRequest,
FunCaptchaComplexImageTaskRequest,
HcaptchaRequest,
HcaptchaComplexImageTaskRequest,
GeetestRequest,
DataDomeCustomTaskRequest,
TenDiCustomTaskRequest,
Expand All @@ -107,10 +102,8 @@ async def solve_captcha(self, request: Union[
RecognitionComplexImageTaskRequest,
MTCaptchaRequest,
YidunRequest,
TemuCustomTaskRequest,
ProsopoTaskRequest,
AltchaCustomTaskRequest,
CastleCustomTaskRequest,
TspdCustomTaskRequest,
HuntCustomTaskRequest,
AlibabaCustomTaskRequest,
Expand Down Expand Up @@ -142,8 +135,6 @@ async def _solve(self, request: Union[
ImageToTextRequest,
FuncaptchaRequest,
FunCaptchaComplexImageTaskRequest,
HcaptchaRequest,
HcaptchaComplexImageTaskRequest,
GeetestRequest,
DataDomeCustomTaskRequest,
TenDiCustomTaskRequest,
Expand All @@ -155,10 +146,8 @@ async def _solve(self, request: Union[
RecognitionComplexImageTaskRequest,
MTCaptchaRequest,
YidunRequest,
TemuCustomTaskRequest,
ProsopoTaskRequest,
AltchaCustomTaskRequest,
CastleCustomTaskRequest,
TspdCustomTaskRequest,
HuntCustomTaskRequest,
AlibabaCustomTaskRequest,
Expand Down
9 changes: 0 additions & 9 deletions capmonstercloud_client/GetResultTimeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def getImage2TextTimeouts() -> GetResultTimeouts:
def getFuncaptchaTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 1, 80)

def getHcaptchaTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getGeetestTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 0, 1, 80)

Expand Down Expand Up @@ -56,9 +53,6 @@ def getImpervaTimeouts() -> GetResultTimeouts:
def getAltchaTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 0, 1, 50)

def getCastleTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 0, 1, 60)

def getTspdTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 0, 1, 60)

Expand All @@ -83,9 +77,6 @@ def getYidunTimeouts() -> GetResultTimeouts:
def getProsopoTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getTemuTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

def getFengkongCloudTimeouts() -> GetResultTimeouts:
return GetResultTimeouts(1, 10, 3, 180)

Expand Down
55 changes: 0 additions & 55 deletions capmonstercloud_client/requests/CastleCustomTaskRequest.py

This file was deleted.

121 changes: 0 additions & 121 deletions capmonstercloud_client/requests/HcaptchaComplexImageTask.py

This file was deleted.

Loading
Loading