Skip to content

Commit a8ed1d3

Browse files
Merge pull request #18 from captcha-solver-api/sdk-review-updates
Sdk review updates
2 parents 5ce5560 + f3738dd commit a8ed1d3

59 files changed

Lines changed: 2437 additions & 990 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/dependabot.yml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependabot opens pull requests that update dependencies. Security updates
2+
# for vulnerable dependencies also require "Dependabot alerts" and
3+
# "Dependabot security updates" to be enabled in the repository settings.
4+
version: 2
5+
updates:
6+
# Runtime and dev dependencies declared in pyproject.toml.
7+
- package-ecosystem: pip
8+
directory: /
9+
schedule:
10+
interval: weekly
11+
commit-message:
12+
prefix: build
13+
14+
# Versions of the actions used in .github/workflows.
15+
- package-ecosystem: github-actions
16+
directory: /
17+
schedule:
18+
interval: weekly
19+
commit-message:
20+
prefix: ci

‎.github/workflows/security.yml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Security
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
# New advisories are published without any change in this repository,
8+
# so re-check the dependencies weekly as well (Mondays, 06:00 UTC).
9+
schedule:
10+
- cron: "0 6 * * 1"
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
16+
# CodeQL is not run here: the repository uses CodeQL default setup
17+
# (Settings -> Code security), and GitHub rejects results from a workflow
18+
# while default setup is enabled.
19+
20+
jobs:
21+
# Known vulnerabilities in the runtime dependencies that users install
22+
# with the package. pip-audit resolves them from pyproject.toml in an
23+
# isolated environment, so the result matches a fresh `pip install`.
24+
dependencies:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.12"
33+
34+
- name: Install pip-audit
35+
run: python -m pip install pip-audit
36+
37+
- name: Audit runtime dependencies
38+
run: pip-audit .
39+
40+
# Static analysis of the SDK source for insecure patterns, such as disabled
41+
# TLS verification, requests without timeouts, or eval/exec.
42+
bandit:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Set up Python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: "3.12"
51+
52+
- name: Install bandit
53+
run: python -m pip install bandit
54+
55+
- name: Scan package source
56+
run: bandit -r captcha_solver_api

‎AGENTS.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Python SDK for the Captcha Solver API, published on PyPI as `captcha-solver-api`
44

55
## Project layout
66

7-
- `captcha_solver_api/` — package: `client.py` (sync), `async_client.py` (async), `tasks.py`, `exceptions.py`
8-
- `tests/sync/`, `tests/async/` — unit tests, HTTP is mocked
9-
- `tests/integration/` — real HTTP requests to a local stub server (`api_server` fixture)
10-
- `examples/sync/`, `examples/async/` — runnable examples
11-
- `DEVELOPMENT.md` — setup, tests, release process
7+
- `captcha_solver_api/` - package: `client.py` (sync), `async_client.py` (async), `tasks.py`, `exceptions.py`
8+
- `tests/sync/`, `tests/async/` - unit tests, HTTP is mocked
9+
- `tests/integration/` - real HTTP requests to a local stub server (`api_server` fixture)
10+
- `examples/sync/`, `examples/async/` - runnable examples
11+
- `DEVELOPMENT.md` - setup, tests, release process
1212

1313
## Commands
1414

‎DEVELOPMENT.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ python -m pytest -k turnstile # filter by name
2727

2828
No API key or internet access is needed:
2929

30-
- `tests/sync/`, `tests/async/` — unit tests, HTTP calls are mocked.
31-
- `tests/integration/` — the client sends real HTTP requests to a server started on
30+
- `tests/sync/`, `tests/async/` - unit tests, HTTP calls are mocked.
31+
- `tests/integration/` - the client sends real HTTP requests to a server started on
3232
`127.0.0.1` by the `api_server` fixture, which records path, headers and body.
3333
Use it to check what actually goes over the wire (e.g. the `X-SDK` header).
3434

‎README.md‎

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ enabled in your editor, hover over `CaptchaClient`, `AsyncCaptchaClient`, their
7575
methods, or a task class such as `RecaptchaV2TaskProxyless` to read the documentation.
7676
Signature help shows argument names, types, and defaults while you type a call.
7777

78+
The `captcha_solver_api/py.typed` file is intentionally empty. It is the standard
79+
[PEP 561](https://peps.python.org/pep-0561/) marker that tells type checkers to use
80+
the inline type annotations shipped with this package.
81+
7882
Docstrings describe parameters, solution fields, exceptions, and usage examples.
7983
Task examples assume an existing synchronous `client`; with `AsyncCaptchaClient`,
8084
use `solution = await client.solve(task)` instead. Async snippets run inside an
@@ -151,15 +155,19 @@ on the target page.
151155
|---|---|---|
152156
| reCAPTCHA v2 | ✅ | ✅ |
153157
| reCAPTCHA v2 Enterprise | ✅ | ✅ |
154-
| reCAPTCHA v3 | ✅ | ❌ |
158+
| reCAPTCHA v3 | ✅ | - |
155159
| Cloudflare Turnstile | ✅ | ✅ |
156160
| GeeTest v3 | ✅ | ✅ |
157161
| GeeTest v4 | ✅ | ✅ |
158-
| Image to Text | ✅ | ❌ |
162+
| Image to Text | ✅ | - |
159163
| Yandex SmartCaptcha | ✅ | ✅ |
160-
| Coordinates (click captcha) | ✅ | ❌ |
164+
| Yandex SmartCaptcha Image | ✅ | - |
165+
| Coordinates (click captcha) | ✅ | - |
161166
| Tencent | ✅ | ✅ |
162167

168+
A dash (`-`) means that this CAPTCHA type has no separate task class that accepts
169+
your own proxy; it does not indicate that solving the CAPTCHA is unsupported.
170+
163171
## Client Reference
164172

165173
Every method below is available on both `CaptchaClient` (sync, `requests`-based) and
@@ -207,14 +215,17 @@ solution -- wraps `create_task()` + `get_task_result()` so you don't poll by han
207215

208216
Returns the `solution` dict once `status` is `"ready"` -- its shape depends on
209217
the task type (see [Captcha Types](#captcha-types)).
210-
Raises `ApiError`, `CaptchaTimeoutError`, or `NetworkError`.
218+
Raises `ValidationError` before any request if `task` is not a task object or a
219+
required task parameter is missing or empty. Otherwise raises `ApiError`,
220+
`CaptchaTimeoutError`, or `NetworkError`.
211221

212222
### `create_task(task, language_pool=None)`
213223

214224
Submits `task` and returns its numeric task ID without waiting for a solution.
215225
Accepts `task` and `language_pool`; it does not accept `timeout`. Use this instead of `solve()` if you need to
216226
manage polling yourself (e.g. checking on many tasks from a different process).
217-
Raises `ApiError`, `CaptchaTimeoutError`, or `NetworkError`.
227+
Raises `ValidationError` before any request if `task` is invalid (same rules as
228+
`solve()`). Otherwise raises `ApiError`, `CaptchaTimeoutError`, or `NetworkError`.
218229

219230
### `get_task_result(task_id)`
220231

@@ -479,7 +490,7 @@ print(result["validate"])
479490
print(result["seccode"])
480491
```
481492
`challenge` is session-specific and expires quickly, so it can't be hardcoded
482-
into a static example -- see [examples/sync/geetest_v3.py](https://github.com/captcha-solver-api/python-sdk/blob/main/examples/sync/geetest_v3.py)
493+
into a static example -- see [examples/sync/geetest_v3_proxyless.py](https://github.com/captcha-solver-api/python-sdk/blob/main/examples/sync/geetest_v3_proxyless.py)
483494
for where the fetch belongs in the flow.
484495

485496
```python
@@ -662,6 +673,16 @@ task lifetime. A local timeout does not cancel a task or mean that the API
662673
failed to solve it. Use `create_task()` and keep its `task_id` if you need to
663674
check the same task later; calling `solve()` again creates a new task.
664675

676+
While polling, `solve()` retries short network failures and HTTP timeouts of
677+
`getTaskResult` on the next poll, so a brief outage does not lose an already
678+
created task. After `poll_retries` (default 3) consecutive failures the error is
679+
raised. API errors are not retried, and `createTask` is never retried because
680+
that could create and pay for a second task. To change the limit:
681+
682+
```python
683+
client.poll_retries = 5
684+
```
685+
665686
### Worker language pool
666687

667688
Set a default `language_pool` once at construction instead of passing it to every call:
@@ -731,13 +752,26 @@ try:
731752
except ValidationError as e:
732753
print(f"Invalid argument: {e}")
733754
except ApiError as e:
734-
print(f"API error: {e.error_code} {e.error_description}")
735-
except CaptchaTimeoutError:
736-
print("Task timed out")
755+
print(f"API error: {e.error_code} {e.error_description} (task {e.task_id})")
756+
except CaptchaTimeoutError as e:
757+
print(f"Task {e.task_id} timed out")
737758
except NetworkError as e:
738759
print(f"Network error: {e}")
739760
```
740761

762+
Every SDK error has a `task_id` attribute. It is set when the error happens
763+
after the task was created (while polling in `solve()` or in `get_task_result()`)
764+
and is `None` otherwise. A polling timeout does not cancel the task, so you can
765+
keep checking it:
766+
767+
```python
768+
try:
769+
result = client.solve(task)
770+
except CaptchaTimeoutError as e:
771+
if e.task_id is not None:
772+
status = client.get_task_result(e.task_id)
773+
```
774+
741775
`TimeoutError` is still exported as a deprecated alias of `CaptchaTimeoutError`.
742776
Avoid importing it by name: it shadows Python's built-in `TimeoutError`.
743777

@@ -751,12 +785,12 @@ sync/async example list, setup steps, expected results, and placeholder guidance
751785
`CAPTCHA_API_KEY` -- they read sample images bundled in
752786
[examples/assets](https://github.com/captcha-solver-api/python-sdk/tree/main/examples/assets), no target page needed.
753787
`python-dotenv` is optional: install it only if you want the scripts to load a `.env` file.
754-
- **Token captchas** (`recaptcha_v2.py`, `recaptcha_v2_enterprise.py`, `recaptcha_v3.py`,
755-
`turnstile.py`, `yandex_smartcaptcha.py`, `geetest_v4.py`, `tencent.py`) use
788+
- **Token captchas** (`recaptcha_v2_*.py`, `recaptcha_v2_enterprise_*.py`, `recaptcha_v3.py`,
789+
`turnstile_*.py`, `yandex_smartcaptcha_*.py`, `geetest_v4_*.py`, `tencent_*.py`) use
756790
placeholder values (`https://example.com/...`, `YOUR_WEBSITE_KEY`, `YOUR_APP_ID`,
757791
`YOUR_CAPTCHA_ID`) -- replace these with the real values from your own target
758792
page before running.
759-
- **`geetest_v3.py`** additionally needs `challenge` fetched fresh for every
793+
- **`geetest_v3_*.py`** additionally needs `challenge` fetched fresh for every
760794
request -- it's single-use and expires within seconds, so it can't be
761795
hardcoded into a static example. `"https://target-site.com/path/to/geetest/init"`
762796
is a placeholder; replace it with a request to your own target's equivalent
@@ -797,8 +831,8 @@ Full API reference: https://captcha-solver.com/en/docs/captcha-types
797831
- [Selenium Python examples](https://github.com/captcha-solver-api/captcha-solver-selenium-python-examples)
798832
- [JavaScript examples](https://github.com/captcha-solver-api/javascript-examples)
799833
- [Tencent CAPTCHA automation examples](https://github.com/captcha-solver-api/How-to-Automate-Tencent-CAPTCHA)
800-
- [Cloudflare Turnstile Puppeteer Demo](https://github.com/captcha-solver-api/cloudflare-turnstile-puppeteer-demo) — a working browser automation example for Cloudflare Turnstile.
801-
- [How to Automate Tencent CAPTCHA](https://captcha-solver.com/en/blog/how-to-automate-tencent-captcha) — a step-by-step guide with Python and JavaScript SDK examples.
834+
- [Cloudflare Turnstile Puppeteer Demo](https://github.com/captcha-solver-api/cloudflare-turnstile-puppeteer-demo) - a working browser automation example for Cloudflare Turnstile.
835+
- [How to Automate Tencent CAPTCHA](https://captcha-solver.com/en/blog/how-to-automate-tencent-captcha) - a step-by-step guide with Python and JavaScript SDK examples.
802836

803837
## License
804838

‎SECURITY.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Security Policy
2+
3+
## Supported versions
4+
5+
Security fixes are provided for the latest released version of
6+
`captcha-solver-api`. Before reporting a vulnerability, verify that it is still
7+
present after upgrading to the latest version available on PyPI.
8+
9+
| Version | Supported |
10+
|---|---|
11+
| Latest release | Yes |
12+
| Older releases | No |
13+
14+
## Reporting a vulnerability
15+
16+
Please report suspected vulnerabilities privately through
17+
[GitHub Security Advisories](https://github.com/captcha-solver-api/python-sdk/security/advisories/new).
18+
Do not open a public issue or pull request for an undisclosed vulnerability.
19+
20+
Include the following information when possible:
21+
22+
- the affected SDK version and Python version;
23+
- a clear description of the impact;
24+
- steps or a minimal example that reproduces the problem;
25+
- any known mitigations or suggested fixes.
26+
27+
You should receive an acknowledgement within five business days. We will keep
28+
you informed while the report is investigated and will coordinate disclosure
29+
after a fix is available. Please allow a reasonable amount of time for the
30+
issue to be addressed before making it public.
31+
32+
## Scope
33+
34+
This policy covers the Python SDK in this repository. Vulnerabilities in the
35+
Captcha Solver service or website should be reported through the security
36+
channel of the corresponding project.

‎captcha_solver_api/_version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.4"
1+
__version__ = "1.1.0"

0 commit comments

Comments
 (0)