How to solve Cloudflare Turnstile Captcha with Python

Sora Fujimoto
AI Solutions Architect
13-May-2024

What is Cloudflare Turnstile
Cloudflare Turnstile is a free tool designed to replace traditional CAPTCHAs. Turnstile provides frustration-free, CAPTCHA-free web experiences for visitors with just a simple snippet of code. Unlike traditional CAPTCHAs, it protects websites from bot traffic without compromising user privacy or user experience.
Key Benefits of Turnstile:
- User-friendly: no more annoying puzzles or image selections.
- Privacy-first: does not track personal data.
- Anti-bot protection: ensures visitors are real and mitigates abuse.
- Lightweight and easy to implement with minimal code.
How to Identify Cloudflare Turnstile Captchas
Turnstile can appear in different forms depending on the context and risk assessment:
-
Non-interactive challenge
- No interaction is required from the user.

Example link
- No interaction is required from the user.
-
Non-intrusive interactive challenge
- A simple click may be required if the visitor is suspected to be a bot.

Example link
- A simple click may be required if the visitor is suspected to be a bot.
-
Invisible challenge
- The captcha is loaded in the HTML but not visible on the page.

Example link
- The captcha is loaded in the HTML but not visible on the page.
🛠️ Solving Cloudflare Turnstile Captcha with Python
⚙️ Prerequisites
- Python installed (Download Python)
- CapSolver API Key
🤖 Step 1: Install Required Packages
bash
pip install requests
👨💻 Step 2: Python Script to Solve Turnstile
python
import time
import requests
CAPSOLVER_API_KEY = "api key"
PAGE_URL = "url"
WEBSITE_KEY = "site key"
def solvecf(metadata_action=None, metadata_cdata=None):
url = "https://api.capsolver.com/createTask"
task = {
"type": "AntiTurnstileTaskProxyLess",
"websiteURL": PAGE_URL,
"websiteKey": WEBSITE_KEY,
}
if metadata_action or metadata_cdata:
task["metadata"] = {}
if metadata_action:
task["metadata"]["action"] = metadata_action
if metadata_cdata:
task["metadata"]["cdata"] = metadata_cdata
data = {
"clientKey": CAPSOLVER_API_KEY,
"task": task
}
response_data = requests.post(url, json=data).json()
print(response_data)
return response_data['taskId']
def solutionGet(taskId):
url = "https://api.capsolver.com/getTaskResult"
status = ""
while status != "ready":
data = {"clientKey": CAPSOLVER_API_KEY, "taskId": taskId}
response_data = requests.post(url, json=data).json()
print(response_data)
status = response_data.get('status', '')
print(status)
if status == "ready":
return response_data['solution']
time.sleep(2)
def main():
taskId = solvecf()
solution = solutionGet(taskId)
if solution:
user_agent = solution['userAgent']
token = solution['token']
print("User_Agent:", user_agent)
print("Solved Turnstile Captcha, token:", token)
if __name__ == "__main__":
main()
⚠️ Variables to Update
- CAPSOLVER_API_KEY: Get your API key from the Capsolver Dashboard.
- PAGE_URL: Replace with the URL of the website where you want to solve Turnstile.
- WEBSITE_KEY: Replace with the Turnstile site key of the website.
✅ Conclusion
By leveraging CapSolver, developers can efficiently bypass Cloudflare Turnstile CAPTCHAs in a secure and automated way. With high accuracy, proxyless support, and minimal setup, this solution is ideal for web scraping, automation, and testing workflows that need to interact with sites protected by Turnstile.
Capsolver’s Python API makes it straightforward to integrate into existing scripts or automation pipelines, allowing you to save time and reduce manual intervention.
❓ FAQ
Q1: Do I need proxies to use Capsolver for Turnstile?
A: No, Capsolver provides proxyless solving, though you can use your own proxies for additional safety if needed.
Q2: How long does it take to solve a Turnstile captcha?
A: Usually a few seconds, depending on the challenge type and network conditions.
Q3: Can this solution handle multiple Turnstile challenges in parallel?
A: Yes, you can create multiple tasks simultaneously to solve challenges concurrently.
Q4: Is it safe to use for production environments?
A: Yes, Capsolver is designed for high reliability and can handle real-time automated workflows without risk to your accounts.
Q5: Are there limitations for the invisible Turnstile challenge?
A: Invisible challenges work the same way as visible ones; Capsolver detects and solves them automatically.
Compliance Disclaimer: The information provided on this blog is for informational purposes only. CapSolver is committed to compliance with all applicable laws and regulations. The use of the CapSolver network for illegal, fraudulent, or abusive activities is strictly prohibited and will be investigated. Our captcha-solving solutions enhance user experience while ensuring 100% compliance in helping solve captcha difficulties during public data crawling. We encourage responsible use of our services. For more information, please visit our Terms of Service and Privacy Policy.
More

How to Automate Cloudflare Challenge Solving in Selenium
Master the definitive strategy for Cloudflare Challenge Solving in Selenium. Use Undetected-Chromedriver, behavioral mimicry, and CapSolver's API for reliable web automation

Ethan Collins
03-Dec-2025

How to Solve Cloudflare Challenge with Node.js
A look at why Cloudflare blocks Node.js scrapers and how developers reliably get cf_clearance for data workflows.

Ethan Collins
03-Dec-2025

Top Cloudflare Challenge Solvers in 2026: Performance Rankings
Discover the Top Cloudflare Challenge Solvers in 2026. We compare CapSolver's superior speed and 99%+ success rate against 5 smaller competitors. Learn why CapSolver is the best choice for web automation.

Aloísio Vítor
11-Nov-2025

How to Solve Cloudflare Captcha with Python & Selenium
Struggling with Cloudflare Captcha? Learn how to tackle it using Python and Selenium! This guide breaks down what Cloudflare Captcha is and offers effective solutions for web scraping in 2024.

Rajinder Singh
10-Nov-2025

How to Solve Cloudflare in 2026: The 6 Best Methods for Uninterrupted Automation
Discover the 6 best methods to solve the Cloudflare Challenge 5s in 2026 for web scraping and automation. Includes detailed strategies, code examples, and a deep dive into the AI-powered CapSolver solution

Ethan Collins
29-Oct-2025

How to Solve the Cloudflare 5s Challenge: A Technical Guide for Web Scraping
Learn how to solve the Cloudflare 5-second challenge using advanced CAPTCHA solver APIs. A step-by-step guide for developers on overcoming Cloudflare JavaScript and Managed Challenges with CapSolver for stable web scraping automation.

Anh Tuan
28-Oct-2025

