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

cloudscraper-turnstile

cloudscraper-turnstile is a drop-in replacement for cloudscraper that solves Cloudflare Turnstile and the 5s "Just a moment..." interstitial. It subclasses requests.Session the same way cloudscraper does, so you change one import line and your existing scraper keeps working, except now the requests that used to return 403 come back with the real page.

import cloudscraper_turnstile as cloudscraper

scraper = cloudscraper.create_scraper(api_key="pk_your_api_key")
resp = scraper.get("https://protected.example.com/")   # Turnstile solved, real page returned

Why cloudscraper can't do this anymore

cloudscraper is a good tool for the challenge it was built for, but that challenge is gone from most sites:

  • It only ever solved the legacy IUAM challenge. cloudscraper works by reading Cloudflare's old "I'm Under Attack Mode" page, extracting the JavaScript math problem, and evaluating it. That is the entire mechanism.
  • It has no JS engine and no browser. Modern Cloudflare managed challenges and Turnstile run real, obfuscated browser JavaScript and collect behavioral and fingerprint signals. There is nothing in the page for a regex-and-eval tool to solve, so the request stays on the challenge page and you get a 403, a 503, or an endless "Just a moment..." loop.
  • Its own "Turnstile support" is a hand-off. cloudscraper never solved Turnstile itself. It added hooks to pass the challenge to a third-party paid CAPTCHA API and inject the returned token. Without one of those API keys configured, Turnstile support does nothing.
  • The project is unmaintained. Its last real release was in 2023. Cloudflare has shipped many detection changes since.

So on any site that switched to Turnstile or the managed 5s challenge (most of them, by now), plain cloudscraper returns the challenge HTML instead of your data. This package fills that gap: it keeps cloudscraper's create_scraper / requests.Session shape and does the one thing cloudscraper cannot, by sending the challenge to a solver that runs a real browser.

Powered by Peak

This package uses Peak to solve Turnstile and the 5s challenge.

  • $0.90 per 1,000 successful Turnstile solves, down to $0.35 at volume
  • Pay only for solves that land. A failed solve is not billed.
  • 1,000 free solves to start, no card.

→ Get your free API key · Docs · Pricing

Install

pip install cloudscraper-turnstile

The only dependency is requests (you already have it if you used cloudscraper).

Migration guide

There is no rewrite. cloudscraper-turnstile mirrors cloudscraper's public API: create_scraper(...) returns a CloudScraper object that subclasses requests.Session, so .get, .post, .request, .cookies, and .headers all behave the same.

Before

import cloudscraper

scraper = cloudscraper.create_scraper()
resp = scraper.get("https://protected.example.com/")   # 403 / "Just a moment..." on Turnstile sites

After

import cloudscraper_turnstile as cloudscraper   # the only line that changes

scraper = cloudscraper.create_scraper()                # reads PEAK_API_KEY from env
resp = scraper.get("https://protected.example.com/")   # Turnstile solved, real page returned

If you were already using cloudscraper's captcha-provider style, that keeps working too, so migration is a no-op:

scraper = cloudscraper.create_scraper(
    captcha={"provider": "peak", "api_key": "pk_your_api_key"},
)

Existing cloudscraper kwargs (browser, delay, interpreter, allow_brotli, sess, ...) are accepted and never raise, so you do not have to touch the rest of your create_scraper call.

Quickstart

pip install cloudscraper-turnstile requests
export PEAK_API_KEY=pk_your_api_key      # Windows: setx PEAK_API_KEY pk_your_api_key
import os
import cloudscraper_turnstile as cloudscraper

scraper = cloudscraper.create_scraper(api_key=os.environ["PEAK_API_KEY"])

# Use it like requests / cloudscraper. A Turnstile or 5s challenge is
# detected, solved through Peak, and the request is retried for you.
resp = scraper.get("https://protected.example.com/")
print(resp.status_code)   # 200
print(resp.text)          # the real page, not the challenge

# Cookies obtained during the solve (including cf_clearance) persist on the
# session for every later request.
resp2 = scraper.post(
    "https://protected.example.com/api/search",
    json={"q": "widgets"},
)

Where the key comes from

The API key is resolved in this order:

  1. Explicit create_scraper(api_key="pk_...")
  2. create_scraper(captcha={"provider": "peak", "api_key": "pk_..."})
  3. PEAK_API_KEY environment variable

Using a proxy

Pass a proxy and it is forwarded to Peak, so the solve happens from the same IP as your crawl (this matters, since Cloudflare ties clearance to the requesting IP):

scraper = cloudscraper.create_scraper(
    api_key="pk_your_api_key",
    proxy="http://user:pass@ip:port",
)

If you set scraper.proxies the requests way instead, the solve uses that proxy too.

Earn with your app ID

Pass your Peak app id and you earn 5% of every solve this tool makes, paid as solve credit. The app_id is optional and only changes who is credited, never whether or how fast a challenge is solved. Create one at peak.fo/dashboard/developer; details at peak.fo/earn.

scraper = cloudscraper.create_scraper(
    api_key="pk_your_api_key",
    app_id="app_your_app_id",   # optional; or set PEAK_APP_ID in the env
)

Compatibility

cloudscraper API Status in cloudscraper-turnstile
create_scraper(**kwargs) Supported. Returns a requests.Session subclass.
Returns a requests.Session Yes. CloudScraper(requests.Session).
.get / .post / .put / .delete / .request Supported (inherited from requests.Session).
.cookies, .headers, .proxies, .auth Supported (session state persists across the solve retry).
sess= (adopt an existing Session) Supported (cookies, headers, proxies, auth carried over).
captcha={"provider": ..., "api_key": ...} Supported. provider: "peak" is native; the api_key is read regardless.
browser=, delay=, interpreter=, allow_brotli=, debug= Accepted, never raise. debug=True prints solve steps.
Legacy IUAM JS-math challenge Handled by Cloudflare's own retry path; not the focus.
Cloudflare Turnstile Solved via Peak (turnstiletask).
Cloudflare 5s "Just a moment" / managed Solved via Peak (cloudflare5stask).

cloudscraper vs cloudscraper-turnstile

Challenge / trait cloudscraper cloudscraper-turnstile
Legacy IUAM JS-math Yes Yes
Cloudflare Turnstile No (hands off to a paid API you must wire up) Yes
5s "Just a moment" interstitial No (no JS engine) Yes
Managed challenge No Yes
requests.Session drop-in Yes Yes
Actively maintained No (last release 2023) Yes

FAQ

Why is cloudscraper not working in 2026? Because the site moved to Cloudflare Turnstile or the managed 5s challenge. cloudscraper only solves the old IUAM JavaScript-math page and has no JS engine, so on a modern challenge it returns the challenge HTML (usually 403, 503, or a "Just a moment..." page) instead of your data. Its last release was in 2023. cloudscraper-turnstile detects those challenges and solves them through Peak.

What is a good cloudscraper alternative for Turnstile? cloudscraper-turnstile is built to be that alternative: same create_scraper API, same requests.Session object, and it solves Turnstile. Change the import, add a Peak API key, and your existing code runs.

How do I fix cloudscraper 403 Forbidden? A 403 from a Cloudflare-protected site means, in most cases, that you received the challenge page, not a real block. Confirm the body contains cf-turnstile, Just a moment, or cf_chl_opt. If so, switch to import cloudscraper_turnstile as cloudscraper, set PEAK_API_KEY, and the package solves the challenge and retries the request. If the proxy/IP that gets challenged is not your default one, pass proxy= so the solve matches.

Does cloudscraper solve Cloudflare Turnstile? Not on its own. cloudscraper never solved Turnstile itself; it only added hooks to pass the token from an external paid CAPTCHA service. cloudscraper-turnstile does the solve for you through Peak and injects the cf-turnstile-response token, so there is nothing else to wire up.

Do I need a real browser or Selenium? No. This is a pure requests-based client. The browser work happens on Peak's side; you send the sitekey and URL and get a token (or a cf_clearance cookie for the 5s challenge) back.

Does it handle the 5s "Just a moment" page too? Yes. When the response is the interstitial rather than a Turnstile widget, the package calls Peak's cloudflare5stask, sets the returned cf_clearance cookie (and user-agent) on the session, and re-requests the original URL.

Will it loop forever if a solve fails? No. Solving is capped by max_solve_attempts (default 3). After that the last response is returned as-is so you can inspect it.

Troubleshooting

The package raises PeakError with a string you can grep for, or hands you back the challenge page when it gives up. Each case, and the two failures that show up after a solve, has a longer write-up on the Peak blog.

  • PeakError: No Peak API key. None of the three sources above had a key. Keys start with pk_; the free one comes from the dashboard.
  • PeakError: Peak request failed: ... The HTTP call to api.peak.fo itself failed: a DNS or TLS error, a proxy that refused the connection, or a timeout. The proxy= you pass is forwarded to Peak for the solve, not used for this call; check your own network path first.
  • PeakError: <error text from Peak> Peak answered with success: false. The text is Peak's own reason, for example an exhausted balance or a sitekey the solver could not clear. The Cloudflare Turnstile error codes post covers the widget-side codes (110200, 300030, 600010 and friends) that often sit behind a failed solve.
  • scraper.get() returns the challenge HTML with no exception. The solve ran up to max_solve_attempts times (default 3) and the site still served a challenge, so the last response comes back as-is. Pass debug=True to create_scraper to print each attempt. The usual cause is an egress mismatch: Cloudflare ties cf_clearance to the IP and User-Agent that earned it, so a clearance solved from Peak's network and replayed from yours gets refused. Pass proxy= (or set scraper.proxies) so the solve and the crawl share one IP. Cloudflare Turnstile 403 walks through the fix.
  • The page had a Turnstile widget but the package took the 5s path. _solve_and_retry goes the Turnstile route only when it finds a data-sitekey in the HTML. A widget rendered by script after load has no sitekey in the raw body, so the package treats the response as an interstitial. How to find a Cloudflare Turnstile sitekey shows where sites hide it, and Turnstile token vs cookie explains which of the two artefacts a given page wants.
  • A later request 403s even though the first one passed. The cf_clearance cookie expired or the site rotated its challenge. The session keeps the cookie, so the next challenged request triggers a fresh solve. The Cloudflare 5-second challenge explained covers how long a clearance lives, and the cf-turnstile-response token explained covers the token side.

Two longer reads for this stack: How to scrape Cloudflare-protected sites without getting blocked (also on Hashnode) and the 2026 Turnstile developer guide.

Same pattern for other stacks: turnstile-curl (the curl_cffi companion, also browserless) · scrapy-turnstile · scrapling-turnstile · playwright-turnstile · patchright-turnstile · camoufox-turnstile · nodriver-turnstile · pydoll-turnstile · drissionpage-turnstile · selenium-turnstile · botasaurus-turnstile · crawlee-turnstile · puppeteer-extra-plugin-turnstile · browser-use-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.

Legitimate use

Use this for automation, QA, monitoring, and scraping public data you are allowed to access. Respect each target's Terms of Service and robots.txt, rate-limit yourself, and do not use it for credential stuffing or to access data you have no right to. You are responsible for how you use it.

License

MIT. See LICENSE.

Metadata

Release files for cloudscraper-turnstile 0.2.2

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

Source distribution (sdist)

Source distribution for cloudscraper-turnstile 0.2.2
File Size Uploaded Provenance Actions
cloudscraper_turnstile-0.2.2.tar.gz 457.7 kB Without provenance Details for cloudscraper_turnstile-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cloudscraper-turnstile 0.2.2
File Interpreter ABI Platform Actions
cloudscraper_turnstile-0.2.2-py3-none-any.whl Python 3 none any Details for cloudscraper_turnstile-0.2.2-py3-none-any.whl

Total release size: 473.6 kB

Release files / cloudscraper_turnstile-0.2.2.tar.gz

Download URL cloudscraper_turnstile-0.2.2.tar.gz
Size 457.7 kB
Tags Source
SHA-256 checksum
How to use checksums
42bfd1c0291974ea33d906bbe580a15c1547f42867f6eb343af8839d70ef0fd3
BLAKE2b-256 checksum
How to use checksums
d262ce1d0443a05df0b6787e52ec0ff656c1dfdc6671535b5fcf7e0c16f8e850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / cloudscraper_turnstile-0.2.2-py3-none-any.whl

Download URL cloudscraper_turnstile-0.2.2-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c097b6ac5366670d75e2ab81dfcaae6312dc7426faeb42daf9d2b2f28653e9d9
BLAKE2b-256 checksum
How to use checksums
9617f99e8c17adb23235b5c90e5e3e36ec8408539cfad6a783c8c0d4e04f74f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for cloudscraper-turnstile 0.2.2

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