Skip to main content

nodriver-turnstile

Solve Cloudflare Turnstile inside a nodriver browser. Read the sitekey off the page, get a token, drop it into the widget. Three lines, and it works with the real Chrome nodriver already drives.

Python 3.9+ nodriver MIT License


nodriver gets you past most bot checks on its own. It's a real Chrome with no CDP fingerprints. What it can't do is answer a Turnstile challenge, because that's a token the widget mints server-side, not something a browser flag turns off. This library fills that one gap: it hands the (url, sitekey) to a solver and puts the returned token back where the page expects it. Everything else (cookies, TLS, the session) stays in your nodriver browser.

Install

pip install nodriver-turnstile

Use it

import asyncio, os
import nodriver as uc
from nodriver_turnstile import solve_turnstile

async def main():
    browser = await uc.start()
    tab = await browser.get("https://site-with-turnstile.example/login")

    result = await solve_turnstile(tab, os.environ["PEAK_API_KEY"])
    print(result.elapsed, result.cost)   # token is already in the page

    await (await tab.select("button[type=submit]")).click()

asyncio.run(main())

That's the whole thing. solve_turnstile finds the sitekey (explicit-render div, implicit div, or the managed iframe), requests a token, fills every cf-turnstile-response field, and fires the widget's callback if the page registered one.

Matching the exit IP

Turnstile scores the IP that submits the token. If your nodriver browser runs behind a proxy, give the solver the same one so the token and the request line up:

result = await solve_turnstile(tab, api_key, proxy="http://user:pass@host:port")

Leave proxy off and the token is minted from a clean pool instead. That's fine for a lot of sites; test it against yours.

Lower-level pieces

You don't have to hand it the tab. Pull the sitekey and token yourself when you want control over injection:

from nodriver_turnstile import read_sitekey, request_token

sitekey = await read_sitekey(tab)
res = await request_token(api_key, url="https://target.example/", sitekey=sitekey)
await tab.evaluate(f'document.querySelector("[name=cf-turnstile-response]").value = {res.token!r}')

Getting a key

solve_turnstile needs an API key for the solver it calls: Peak. You pay only for the solves that land, and the free tier (1,000 solves, no card) is enough to wire this up and test it end to end. Peak also solves the Cloudflare 5-second challenge (task_type: "cloudflare5stask"); this package covers Turnstile.

Peak
$0.90 per 1,000 Turnstile solves, down to $0.35 at volume · pay only on success · 1,000 free solves · peak.fo

Troubleshooting

The failures people report with this package come down to a short list. Each one has a longer write-up on the Peak blog.

  • TurnstileError: no Turnstile sitekey on the page after 15s. read_sitekey polls the DOM for 15 seconds and gives up. The widget had not rendered yet, or the site loads it from a script the selectors never see. Navigate first, wait for .cf-turnstile or the challenges.cloudflare.com iframe, then call solve_turnstile. If the sitekey lives somewhere odd, read it by hand and call request_token with it. How to find a Cloudflare Turnstile sitekey covers the DevTools route and the places sites hide it (also on Hashnode).
  • TurnstileError: got a token but found nowhere to put it. The solve worked. The page has no cf-turnstile-response input and no data-callback, which happens on widgets rendered through the JS API with a callback closure. Use request_token and hand the token to the page's own handler with tab.evaluate.
  • cf-turnstile-response is empty when your own code reads it. You read the field before the solve returned, or the page re-rendered the widget after injection and wiped the hidden input. Await solve_turnstile, then click submit in the same step. cf-turnstile-response is empty lists the causes in order, and the cf-turnstile-response token explained covers what the server does with the token once it arrives.
  • The page still answers 403 after the token lands. That is a different wall. A Turnstile token satisfies a widget on a form. A 403 interstitial wants a cf_clearance cookie from the 5-second challenge, which is Peak's cloudflare5stask, not this package. Turnstile token vs cookie explains which one you need, Cloudflare Turnstile 403 walks through the fix, and the Cloudflare 5-second challenge explained covers the cookie side.
  • The widget shows an error code such as 110200, 300030 or 600010. Cloudflare Turnstile error codes groups them by what failed, from a domain missing on the sitekey's allowlist to a challenge run that died inside the iframe.

For the bigger picture, including why the proxy you pass to Peak should match the browser's egress IP, read How to solve Cloudflare Turnstile in 2026.

Same pattern for other stacks: pydoll-turnstile · drissionpage-turnstile · patchright-turnstile · playwright-turnstile · camoufox-turnstile · selenium-turnstile · botasaurus-turnstile · scrapling-turnstile · crawlee-turnstile · puppeteer-extra-plugin-turnstile · browser-use-turnstile · scrapy-turnstile · turnstile-curl · cloudscraper-turnstile · crawl4ai-turnstile. Full list in awesome-turnstile-solvers.

If you want to know what the widget does before it hands out a token, cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting it runs.

Notes

Use this on sites and accounts you're allowed to automate. Respect each target's Terms of Service and robots.txt. This is tooling for legitimate automation, testing, and public-data scraping; nothing here helps with credential stuffing or abuse. Not affiliated with Cloudflare.

License

MIT

Metadata

Release files for nodriver-turnstile 0.1.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 nodriver-turnstile 0.1.1
File Size Uploaded Provenance Actions
nodriver_turnstile-0.1.1.tar.gz 7.9 kB Without provenance Details for nodriver_turnstile-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nodriver-turnstile 0.1.1
File Interpreter ABI Platform Actions
nodriver_turnstile-0.1.1-py3-none-any.whl Python 3 none any Details for nodriver_turnstile-0.1.1-py3-none-any.whl

Total release size: 15.7 kB

Release files / nodriver_turnstile-0.1.1.tar.gz

Download URL nodriver_turnstile-0.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
22baa44ac168f74d0f23dca8f7410eaad629dbf996631c444fb1d950b9f28cd7
BLAKE2b-256 checksum
How to use checksums
d4010cabc4984c2718dee946eca9f1ac28b85c8416c07cc73ddc4f50494bbc02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / nodriver_turnstile-0.1.1-py3-none-any.whl

Download URL nodriver_turnstile-0.1.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8852964577e18c1d199f010825bd6138e8aa5f2f9e40b1b5de80c830a35eba5
BLAKE2b-256 checksum
How to use checksums
70d8d66bc68186bf6eba9d1e313e08ccea6a31855e8efa4d146022773806807a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for nodriver-turnstile 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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