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 Pass Cloudflare Verifying You Are Human Without Getting Stuck
Stuck on "verifying you are human" or "Cloudflare Challenge"? Learn the common causes and discover the technical solutions for automated systems to pass the verification every time.

Ethan Collins
19-Jan-2026

How to Solve Cloudflare in 2026: Solve Cloudflare Turnstile and Challenge By Using CapSolver
Explore Cloudflare's Challenge and Turnstile CAPTCHA and learn how to bypass them using CapSolver, automated browsers, and high-quality proxies. Includes practical Python and Node.js examples for seamless CAPTCHA solving in automation tasks.

Ethan Collins
12-Jan-2026

How to Solve Cloudflare by Using Python and Go in 2026
Will share insights on what Cloudflare Turnstile is, using Python and Go for these tasks, whether Turnstile can detect Python scrapers, and how to effectively it using solutions like CapSolver.

Lucas Mitchell
09-Jan-2026

How to Solve Turnstile Captcha: Tools and Techniques in 2026
Provide you with practical tips and some ways to uncover the secrets of solving turnstile CAPTCHAs efficiently.

Sora Fujimoto
09-Jan-2026

How to Bypass Cloudflare Challenge While Web Scraping in 2026
Learn how to bypass Cloudflare Challenge and Turnstile in 2026 for seamless web scraping. Discover Capsolver integration, TLS fingerprinting tips, and fixes for common errors to avoid CAPTCHA hell. Save time and scale your data extraction.

AloĂsio VĂtor
07-Jan-2026

Cloudflare Challenge vs Turnstile: Key Differences and How to Identify Them
nderstand the key differences between Cloudflare Challenge vs Turnstile and learn how to identify them for successful web automation. Get expert tips and a recommended solver.

Lucas Mitchell
10-Dec-2025

