Skip to main content
Peak: solve Cloudflare Turnstile and the 5-second challenge

selenium-turnstile

selenium-turnstile is a Selenium helper that solves Cloudflare Turnstile by injecting a Peak-solved token, so a protected form or navigation proceeds without a real mouse click.

Why

SeleniumBase's UC-mode click-solve (uc_gui_click_captcha) drives a physical click on the widget, which needs a real display and fails headless on datacenter IPs. undetected-chromedriver has no click-solve at all and gets stuck in the "Just a moment" loop, reloading the interstitial again and again.

This helper skips the click. It reads the sitekey from the DOM, gets a token from Peak, and injects that token as the cf-turnstile-response value and calls the widget's success callback. You need a Peak API key and one function call.

Powered by Peak

This package uses Peak to solve Turnstile.

  • Solves Cloudflare Turnstile and the 5-second challenge
  • $0.90 per 1,000 successful Turnstile solves, down to $0.35 at volume
  • You pay only for solves that land. 1,000 free solves to start, no card. → Get your free API key · Docs · Pricing

Install

pip install selenium-turnstile selenium

Quickstart

import os
from selenium import webdriver
from selenium_turnstile import solve_turnstile

os.environ["PEAK_API_KEY"] = "pk_your_api_key"

driver = webdriver.Chrome()
driver.get("https://protected.example/login")

# Reads the sitekey from the page, solves via Peak, injects the token.
token = solve_turnstile(driver)

driver.find_element("css selector", "form").submit()

Works unchanged with a plain Selenium driver, a SeleniumBase Driver, or an undetected-chromedriver Chrome. All three expose the current_url / find_element / execute_script interface the helper uses.

How it works

  1. Read the sitekey. find_element looks for the data-sitekey attribute on the .cf-turnstile widget; if the sitekey is only set through a JS render() call, an execute_script DOM scan finds it.
  2. Solve via Peak. POST https://api.peak.fo/solve with task_type: "turnstiletask", the sitekey, and url=driver.current_url. Pass proxy= to mint the token from your browser's egress IP.
  3. Inject the token. execute_script sets every cf-turnstile-response field, fires input/change events, and calls the widget's data-callback success handler so the form or navigation continues.

API

solve_turnstile(
    driver,               # any Selenium-like WebDriver
    api_key=None,         # defaults to env PEAK_API_KEY
    proxy=None,           # optional http://user:pass@ip:port, forwarded to Peak
    sitekey=None,         # override auto-detection (e.g. widget in a frame)
    url=None,             # defaults to driver.current_url
    task_type="turnstiletask",
    timeout=180.0,
    app_id=None,          # optional; earns you a share of each solve
) -> str                  # the injected token

Helpers read_sitekey(driver) and inject_token(driver, token) are exposed for finer control. Peak also supports task_type="cloudflare5stask" for the 5s interstitial challenge.

The API key is read from the PEAK_API_KEY environment variable by default; you can also pass api_key=. Never hardcode a real key.

Earn with your app ID

Pass app_id="app_your_id" (or set the PEAK_APP_ID environment variable) to earn 5% of every solve routed through this package, paid as Peak solve credit. It is optional and does not change whether a solve succeeds or how fast it returns.

solve_turnstile(driver, app_id="app_your_id")   # or: export PEAK_APP_ID=app_your_id

Create an app id at peak.fo/dashboard/developer; details at peak.fo/earn.

Troubleshooting

Every failure raises PeakError. The message tells you which step broke.

  • PeakError: No Turnstile sitekey found on the page. read_sitekey looks once and does not wait. If the widget renders after load, wait for it first: WebDriverWait(driver, 15).until(lambda d: d.find_elements("css selector", "[data-sitekey]")). A widget built by turnstile.render() inside a script bundle may leave no data-sitekey in the DOM. Copy the key from the network tab and pass sitekey=. How to find a Cloudflare Turnstile sitekey shows where sites hide it.
  • PeakError: No Peak API key. Neither api_key= nor PEAK_API_KEY held a key. Keys start with pk_; the free one comes from the dashboard.
  • PeakError: Peak request failed: ... The request never reached Peak. Check DNS, the firewall, and any HTTPS_PROXY variable in the environment, since urllib honours it.
  • PeakError with Peak's own reason, or Peak solve failed. Peak answered with success: false. Common causes: an empty balance, a sitekey that does not belong to the URL, or a proxy= Peak could not connect through. Peak does not bill a failed solve. The Cloudflare Turnstile error codes post covers the widget-side codes (110200, 300030, 600010 and the rest).
  • The token comes back and the submit button stays disabled. The injector fills every cf-turnstile-response field and calls the function named in the widget's data-callback attribute. A site that passes a closure to turnstile.render({callback: ...}) keeps that function out of reach. Submit the form yourself with driver.execute_script("document.querySelector('form').submit()"), or call the site's own handler with the token. cf-turnstile-response is empty and the cf-turnstile-response token explained cover the field.
  • The submit returns 403 or the form page again. The site refused the token. A token is single-use and expires 300 seconds after Cloudflare issues it, so submit right away. Pass proxy= with the browser's own egress so Peak mints the token from the address that submits it. Cloudflare Turnstile 403 covers the refusal.
  • driver.get() lands on "Just a moment..." and never leaves. That page is the managed 5-second challenge, a separate check from the Turnstile widget. It wants a cf_clearance cookie, and this helper injects widget tokens. Turnstile token vs cookie explains the difference, and the Cloudflare 5-second challenge explained covers the interstitial.

Two longer reads for this stack: How to solve Cloudflare Turnstile in Selenium (Python) and the 2026 Turnstile developer guide.

Same pattern for other stacks: playwright-turnstile · patchright-turnstile · nodriver-turnstile · camoufox-turnstile · pydoll-turnstile · drissionpage-turnstile · botasaurus-turnstile · scrapling-turnstile · scrapy-turnstile · cloudscraper-turnstile (a requests.Session drop-in, no browser) · turnstile-curl · crawlee-turnstile · puppeteer-extra-plugin-turnstile · browser-use-turnstile · crawl4ai-turnstile. Full list in awesome-turnstile-solvers.

cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting the widget runs before it hands out a token.

Legitimate use

For automation, QA, and scraping public data you are allowed to access. Respect each target's Terms of Service and robots directives, and do not use this for credential-stuffing or other abuse.

License

MIT. See LICENSE.

Metadata

Release files for selenium-turnstile 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selenium-turnstile 0.2.1
File Size Uploaded Provenance Actions
selenium_turnstile-0.2.1.tar.gz 449.3 kB Without provenance Details for selenium_turnstile-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for selenium-turnstile 0.2.1
File Interpreter ABI Platform Actions
selenium_turnstile-0.2.1-py3-none-any.whl Python 3 none any Details for selenium_turnstile-0.2.1-py3-none-any.whl

Total release size: 459.3 kB

Release files / selenium_turnstile-0.2.1.tar.gz

Download URL selenium_turnstile-0.2.1.tar.gz
Size 449.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6797cae485b55e3131fc4b9664bfd6a1892ec0042ffcd4c970a6c68057114221
BLAKE2b-256 checksum
How to use checksums
c2b4569be5f752a8537faefc80215d6ee58f1cec80348f2364b081385dacf3df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / selenium_turnstile-0.2.1-py3-none-any.whl

Download URL selenium_turnstile-0.2.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be59d614191a223d020cab2dd8591b0688ed6b00b3931e0eb96ae90b91ee5440
BLAKE2b-256 checksum
How to use checksums
8dbe597578c117937017b27bbea7a12b9aca07798e913d7a9184b03487ca0e42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for selenium-turnstile 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page