How to Bypass Cloudflare Turnstile in Python (Step-by-Step)

Cloudflare Turnstile is the "Verify you are human" widget that has replaced classic CAPTCHAs on a large share of login, signup and checkout forms. It runs a set of browser checks in the background and, when it is happy, writes a one-time token into the form. The server then verifies that token with Cloudflare before accepting the request.

That design is exactly why a plain requests.post() fails: without a valid token the form is rejected, and the token can only be produced by a real browser environment that passes Cloudflare's checks.

In this guide you will solve Turnstile from Python in three steps:

  1. Find the Turnstile site key on the target page.
  2. Ask a solving API (SolverCF) for a valid token.
  3. Submit the token with your request — using the same User-Agent that solved it.

Only automate sites you own or have permission to test, and respect each site's terms of service.

What you need

  • Python 3.8+ and the requests package (pip install requests)
  • A SolverCF account and its client key from the dashboard. New accounts get 100 free solves automatically.

Step 1: Find the Turnstile site key

Every Turnstile widget is created with a public site key that starts with 0x4. It usually appears in the HTML in one of two ways:

HTML
<div class="cf-turnstile" data-sitekey="0x4AAAAAAAB__YGWiObopXheP"></div>

or inside a script that renders the widget explicitly:

JavaScript
turnstile.render('#captcha', { sitekey: '0x4AAAAAAAB__YGWiObopXheP' });

You can pull it out of the page with a short regex:

Python
import re
import requests

def find_site_key(page_url: str) -> str:
    html = requests.get(page_url, timeout=30).text
    match = (re.search(r'data-sitekey="(0x4[\w-]+)"', html)
             or re.search(r"sitekey['\"]?\s*[:=]\s*['\"](0x4[\w-]+)", html))
    if not match:
        raise ValueError("Turnstile site key not found — the widget may be injected by JavaScript")
    return match.group(1)

If the widget is injected by JavaScript after page load, open the page in your browser's DevTools, search the Elements panel for sitekey, and copy it. Site keys rarely change, so you can hard-code them.

Step 2: Solve the token with the API

SolverCF works asynchronously: you create a task, then poll for its result. A Turnstile solve normally completes in a few seconds.

Python
import time
import requests

API = "https://solvercf.com/token/extension"
CLIENT_KEY = "YOUR_CLIENT_KEY"

def solve_turnstile(website_url: str, website_key: str, timeout: int = 90) -> dict:
    # 1. create the task
    created = requests.post(f"{API}/createTask", json={
        "clientKey": CLIENT_KEY,
        "task": {
            "type": "TurnstileTask",
            "websiteUrl": website_url,
            "websiteKey": website_key,
        },
    }, timeout=30).json()

    if created.get("errorId") != 0:
        raise RuntimeError(f"createTask failed: {created.get('errorDescription')}")
    task_id = created["taskId"]

    # 2. poll every 1.5 seconds until it is ready
    deadline = time.time() + timeout
    while time.time() < deadline:
        time.sleep(1.5)
        result = requests.post(f"{API}/getTaskResult", json={
            "clientKey": CLIENT_KEY,
            "taskId": task_id,
        }, timeout=30).json()

        if result.get("errorId") != 0:
            raise RuntimeError(f"getTaskResult failed: {result.get('errorDescription')}")
        if result["status"] == "ready":
            return result["solution"]          # {"token": ..., "userAgent": ...}
        if result["status"] in ("failed", "expired"):
            raise RuntimeError(f"task {result['status']}")

    raise TimeoutError("Turnstile was not solved in time")

The solution object contains two fields you need:

Field What to do with it
token Send it to the target site, usually as the cf-turnstile-response form field
userAgent Use this exact User-Agent for the request that submits the token

You are only charged when a task reaches ready — failed or expired tasks are free. See pricing for the current per-solve price.

Step 3: Submit the token

Turnstile writes its token into a hidden input named cf-turnstile-response, so a normal form post just includes that field. Put everything together:

Python
LOGIN_URL = "https://example.com/login"

site_key = find_site_key(LOGIN_URL)
solution = solve_turnstile(LOGIN_URL, site_key)

session = requests.Session()
session.headers["User-Agent"] = solution["userAgent"]   # must match the solver

response = session.post(LOGIN_URL, data={
    "email": "[email protected]",
    "password": "your-password",
    "cf-turnstile-response": solution["token"],
}, timeout=30)

print(response.status_code)

Some sites send the token in a JSON body or a custom header instead of a form field. Open DevTools → Network, submit the form once by hand, and copy the exact field name the site uses.

Common problems

The site still rejects the token. Tokens are single-use and expire after about five minutes. Solve right before you submit, never reuse a token, and make sure the User-Agent header matches solution.userAgent.

ERROR_KEY_DOES_NOT_EXIST. Your client key is wrong. Copy it again from the dashboard.

The page shows "Just a moment..." instead of a form. That is a Cloudflare Challenge page, not a Turnstile widget. You need a cf_clearance cookie rather than a token — follow How to Get the cf_clearance Cookie with Python.

I need tokens faster. For high-volume work on popular site keys, the pre-solved token pool returns a token instantly instead of solving on demand.

Wrapping up

Bypassing Turnstile from Python comes down to three things: the right site key, a fresh token per request, and a matching User-Agent. The full parameter reference — including optional proxy and userAgent inputs — is in the Cloudflare Turnstile docs.

Using a browser instead of requests? See the guides for Playwright and Selenium.