跳到正文

kowalski76057

cf-turnstile-token

Scriptable Cloudflare Turnstile token CLI via the Peak API - sitekey discovery, solve, and token output for CI and automation.

README 已保存到本站,可直接阅读

Documentation snapshot

README 快照

本页保存的是公开项目资料快照,阅读过程不需要连接 GitHub。

Cloudflare Turnstile Token

A scriptable command-line client for obtaining Cloudflare Turnstile tokens via the Peak API — built for CI pipelines, QA automation, and integration engineering where a headless, repeatable token flow is required.

Turnstile Token CLI reads a Turnstile sitekey directly from a page (or accepts one explicitly), submits a solve task to the Peak API, and returns a valid cf-turnstile-response token you can inject into a request or form. It has no browser dependency, no interactive steps, and is designed to run anywhere a plain Python 3.8+ runtime exists.

Why

Cloudflare Turnstile walls stop headless and scripted clients with a 403 or a widget they cannot pass. Standing up a real browser per token is slow, flaky, and expensive at scale. A token API removes the browser entirely: hand the service the sitekey and the target URL, and get back a token that submits like a real visitor. Turnstile Token CLI wraps that API in a clean, scriptable interface with automatic sitekey extraction, retries, and structured output.

Features

  • Automatic sitekey extraction — point it at any page and it finds the data-sitekey for you.
  • Zero browser dependency — a single Python file, no Playwright/Selenium, no GUI, works on headless servers and CI runners.
  • Retry with backoff — transient failures retry automatically.
  • Structured output — plain token or JSON, ready to pipe into other tools.
  • Proxy-aware — pass a proxy so the solve matches your crawl IP.
  • Action / cdata support — matches Turnstile configurations that require them.

Quick start

$ export PEAK_API_KEY=pk_your_api_key
$ python cf_turnstile_token.py \
    --page https://example.com/protected \
    --url https://example.com/
sitekey: 0x4AAAAAAAxxxx
0.AgAAABBqzz...

Or with an explicit sitekey and a proxy:

$ python cf_turnstile_token.py \
    --sitekey 0x4AAAAAAAxxxx \
    --url https://example.com/ \
    --proxy http://user:pass@1.2.3.4:8080
0.AgAAABBqzz...

JSON output for pipelines:

$ python cf_turnstile_token.py \
    --page https://example.com/ \
    --url https://example.com/ \
    --output json
{
  "token": "0.AgAAABBqzz...",
  "success": true
}

Installation

No dependencies beyond the Python standard library. Copy cf_turnstile_token.py anywhere, or install as a module:

$ pip install .

Then use the entry point:

$ turnstile-token --page https://example.com/ --url https://example.com/

How it works

  1. Sitekey discovery — if --page is given, the tool fetches the page and extracts the first Turnstile data-sitekey.
  2. Solve request — it POSTs a turnstiletask to the Peak API (https://api.peak.fo/solve) with the sitekey, target URL, and optional proxy/action/cdata.
  3. Token returned — the response carries a data.token you submit as cf-turnstile-response (or the equivalent parameter your target expects).

The API contract is documented at peak.fo/docs/turnstile.

API reference

solve(api_key, sitekey, url, proxy=None, action=None, cdata=None, ...)

ArgumentRequiredDescription
api_keyyesPeak API key (or PEAK_API_KEY env var).
sitekeyyesTurnstile sitekey, e.g. 0x4AAAAAAAxxxx.
urlyesTarget page URL — must end with /.
proxynohttp://user:pass@ip:port to match your crawl IP.
actionnoTurnstile action value, when the site configures one.
cdatanoTurnstile cdata value, when the site configures one.
retriesnoAutomatic retries on transient failure (default 3).

Returns a SolveResult with .token and .raw. Raises PeakError on failure.

extract_sitekey(html)

Scans a page body for the first Turnstile sitekey and returns it (or None).

Examples

Inside a Python script

from turnstile_token_cli import solve, PeakError, extract_sitekey, read_page

html = read_page("https://example.com/protected")
sitekey = extract_sitekey(html)

try:
    result = solve("pk_...", sitekey, "https://example.com/")
    print(result.token)  # -> "0.AgAAABBqzz..."
except PeakError as exc:
    print(f"solve failed: {exc}")

CI / shell

TOKEN=$(python cf_turnstile_token.py --page https://example.com/ --url https://example.com/)
curl -X POST https://example.com/submit \
  -H "cf-turnstile-response: $TOKEN" \
  -d "payload=..."

Configuration

SettingSource
PEAK_API_KEYenvironment variable, or --api-key
--api-urloverride the solve endpoint (default https://api.peak.fo/solve)
--retriesnumber of retry attempts on transient failure

Powered by Peak

This package uses Peak to solve Turnstile.

  • Solve Cloudflare Turnstile & the 5s challenge in about a second
  • Pay only for successful solves - from $1 / 1,000
  • Free API key, no card. Use code PEAKGH for bonus trial credit.

Get your free API key • Docs • Pricing

License

MIT

Official distribution

获取与安装

暂未发现可确认的官方软件包地址

当前 README 快照没有出现 npm、PyPI、Crates.io、pub.dev 等官方包页链接。本站不会根据仓库名称猜测下载地址。

本站不托管项目文件;需要安装时,请以项目维护者发布的官方文档为准。

使用前核验

本站保存公开资料用于阅读,不代表安全审计或功能背书。安装前请核对许可证、依赖来源和发布签名,不要直接运行来源不明的二进制文件或高权限脚本。