Cloudflare Turnstile is a smart CAPTCHA alternative designed to verify users without intrusive challenges. Unlike traditional CAPTCHAs that require image selection or text input, Turnstile runs invisible browser challenges to determine whether the visitor is human. It is widely adopted by websites using Cloudflare's services, and it can be a significant obstacle for web scraping and automation workflows.
Before getting started, make sure you have Python 3.7 or higher installed. You also need a NextCaptcha API key — sign up at NextCaptcha to get free trial credits. Then install the NextCaptcha Python SDK:
First, create a NextCaptchaAPI instance with your API key. You can find your client key in the NextCaptcha dashboard:
from nextcaptcha import NextCaptchaAPIapi = NextCaptchaAPI(client_key="YOUR_CLIENT_KEY")
Now call the turnstile method with the target website URL and the Turnstile site key. The site key can be found in the data-sitekey attribute of the Turnstile widget on the target page:
If you prefer not to use the SDK, you can call the NextCaptcha API directly using the requests library. This approach gives you full control over the HTTP requests:
This approach involves two API calls: createTask to submit the Turnstile challenge, and getTaskResult to poll for the solution. The polling interval of 3 seconds is recommended to avoid rate limiting.
In this guide, we covered two methods to bypass Cloudflare Turnstile with Python: using the NextCaptcha Python SDK for a simple, high-level approach, and using the raw API for full control. NextCaptcha handles the Turnstile challenge solving automatically, returning a valid token that you can submit to the target website. For more details, check the links below: