DEV Community

Arson
Arson

Posted on

Solve Cloudflare Turnstile in Python (3 Lines of Code)

The Problem

Your Python script hits a page protected by Cloudflare Turnstile and gets blocked. You need a valid cf-turnstile-response token to submit forms or access content.

Most solutions involve:

  • Running Selenium with stealth plugins (gets detected)
  • Paying 2Captcha $1/1000 solves with API keys and account setup
  • Giving up and finding a different data source

The Fix: 3 Lines

pip install gatesolve
Enter fullscreen mode Exit fullscreen mode
from gatesolve import GateSolve

client = GateSolve(api_key="gs_YOUR_API_KEY")
token = client.solve(
    type="cloudflare-turnstile",
    site_key="0x4AAAA...",  # from the page source
    page_url="https://example.com",
)

# Use the token in your form submission
print(token)  # Valid cf-turnstile-response token
Enter fullscreen mode Exit fullscreen mode

How It Works

  1. You send the CAPTCHA details (type, site key, page URL)
  2. GateSolve navigates a real browser (Camoufox - patched Firefox) to the page
  3. The browser solves the Turnstile widget like a human would
  4. You get back a valid token in ~9 seconds

The SDK handles the async polling internally. Under the hood it submits the job, polls every 3 seconds, and returns the token when ready.

Getting Your API Key

Free tier: 100 solves, no credit card.

curl -X POST https://gatesolve.dev/api/waitlist \
  -H "Content-Type: application/json" \
  -d x27{"email": "you@example.com"}x27
Enter fullscreen mode Exit fullscreen mode

You get back a gs_ prefixed API key immediately.

Finding the Site Key

Look in the page source for:

<div class="cf-turnstile" data-sitekey="0x4AAAA..."></div>
Enter fullscreen mode Exit fullscreen mode

Or in the network tab, look for requests to challenges.cloudflare.com containing the site key.

Full Example: Scraping a Turnstile-Protected Page

import requests
from gatesolve import GateSolve

client = GateSolve(api_key="gs_YOUR_KEY")

# Solve the CAPTCHA
token = client.solve(
    type="cloudflare-turnstile",
    site_key="0x4AAAAAAAxxxxxxxx",
    page_url="https://protected-site.com/login",
)

# Submit the form with the token
response = requests.post("https://protected-site.com/login", data={
    "username": "user",
    "password": "pass",
    "cf-turnstile-response": token,
})

print(response.status_code)  # 200
Enter fullscreen mode Exit fullscreen mode

Supported CAPTCHA Types

Type Value Price Avg Time
Cloudflare Turnstile cloudflare-turnstile $0.02 ~9s
reCAPTCHA v2 recaptcha-v2 $0.03 ~12s
reCAPTCHA v3 recaptcha-v3 $0.02 ~8s
hCaptcha hcaptcha $0.03 ~10s

Why Not Selenium + Stealth?

Cloudflare detects headless browsers through:

  • Canvas fingerprint hashes
  • WebGL renderer strings
  • Font enumeration order
  • Navigator property inconsistencies

Stealth plugins patch JavaScript APIs but Cloudflare checks at a deeper level. GateSolve uses Camoufox which patches Firefox at the C++ level, generating genuine fingerprints that pass detection.

Links


Built by @ArsonxDev. Questions? Drop a comment.

Top comments (0)