How to Fix Common Cloudscraper Issues & Errors

Cloudscraper is a Python module built on Requests that gets past Cloudflare's anti-bot page, the "I'm Under Attack Mode" challenge. It solves Cloudflare's JavaScript challenges with a JavaScript interpreter, so your scraper looks like a regular browser without you having to deobfuscate Cloudflare's code yourself. It works until it doesn't, and the most common failure happens before a single request goes out: ModuleNotFoundError: No module named 'cloudscraper'.

That import error usually means the package was installed into a different Python environment from the one running your script. A second pip install in the wrong place won't fix it. The other problems show up later, once the script is running. Your requests start returning a CAPTCHA, or you get stuck in a challenge loop that never resolves, because Cloudflare changes its techniques periodically and Cloudscraper has to catch up.

I've spent countless hours working around Cloudflare's evolving security measures while building and maintaining scraping systems. This guide goes through the Cloudscraper problems I run into most often, starting with installation and import errors and moving on to Cloudflare blocks. For each one, it explains what causes the problem and how to fix it.

Why you can trust this guide

Cloudscraper is a useful tool for bypassing Cloudflare, but it's not bulletproof. Cloudflare keeps changing what it checks, so what works today can fail next month. I've been in the trenches debugging and updating, and I've dealt with the headaches so you don't have to.

One caveat before you start: the Cloudscraper project is no longer actively maintained, so "upgrade to the latest version" has a shelf life as a fix. Most of the errors below still come down to configuration, versions, or the site itself, and those are solvable. But if a target has moved past what Cloudscraper can handle, the fix is a different tool rather than more tuning, and this guide says so where that applies.

These fixes for common Cloudscraper errors all come from production scraping projects. Whether you're new to Cloudscraper or knee-deep in debugging, you'll find something that helps.

Step 1: Fix Installation Issues

One of the most common errors occurs before you've even started scraping: installation problems. Let's address these first.

Python Installation Errors

If you're encountering ModuleNotFoundError: No module named 'cloudscraper', follow these steps:

Verify the installation:

import cloudscraper
scraper = cloudscraper.create_scraper()
print("Installation successful!")

Check for environment issues: If you're using virtual environments, make sure you've activated the correct one:

# For venv
source venv/bin/activate  # Linux/Mac
venv\Scripts\activate     # Windows

# For conda
conda activate your_environment_name

Install or reinstall Cloudscraper:

pip install cloudscraper --upgrade

Verify your Python version:

python --version

Cloudscraper works best with Python 3.6+.

Node.js Installation Errors

For Node.js users seeing Error: Cannot find module 'cloudscraper':

  1. Check your package.json: Make sure cloudscraper is listed in your dependencies.

Test the installation:

const cloudscraper = require('cloudscraper');
console.log("Installation successful!");

Install required dependencies:

npm install request request-promise --save

Cloudscraper requires these packages to function properly.

Ensure proper installation:

npm install cloudscraper --save

Step 2: Resolve CAPTCHA Errors

CAPTCHA errors are common with Cloudscraper, especially as Cloudflare updates its protection mechanisms.

Identifying CAPTCHA Errors

Typical error messages include:

  • CaptchaError: captcha
  • Error code: 1 - Cloudflare returned CAPTCHA

Solutions

Rotate IP addresses:Use residential proxies to prevent IP-based CAPTCHA triggers:

scraper = cloudscraper.create_scraper()
response = scraper.get(url, proxies={
    'http': 'http://username:[email protected]:8080',
    'https': 'http://username:[email protected]:8080'
})

Implement delay between requests:Add delays to avoid triggering CAPTCHAs:

import time

# Make request
response = scraper.get(url)
# Wait before next request
time.sleep(10)

Adjust browser emulation:

scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'chrome',
        'platform': 'windows',
        'mobile': False
    }
)

Use CAPTCHA solving services:For Python:

scraper = cloudscraper.create_scraper(
    captcha={
        'provider': '2captcha',
        'api_key': 'your_2captcha_api_key'
    }
)

For Node.js, check if your version supports CAPTCHA solving (later versions may).

Step 3: Handle JavaScript Challenge Failures

Cloudflare uses JavaScript challenges to verify browsers, which can cause issues for Cloudscraper.

Common JavaScript Challenge Errors

  • CloudflareChallengeError: Detected a Cloudflare version 2 challenge
  • Error code: 3 - Failed to parse Cloudflare challenge

Solutions

Fall back to browser automation:When Cloudscraper can't handle challenges, use Selenium or Playwright:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto(url)
    content = page.content()
    browser.close()

Modify TLS settings:For Node.js, modify cipher suites to match Cloudflare expectations:

const cloudscraper = require('cloudscraper').defaults({
    ciphers: 'ECDHE-RSA-AES128-GCM-SHA256'
});

Update Cloudscraper:Cloudflare frequently updates its challenges, requiring Cloudscraper updates:

pip install cloudscraper --upgrade  # Python
npm update cloudscraper             # Node.js

Ensure JavaScript interpreter is installed:For Python, install a JavaScript engine:

pip install js2py

Or use Node.js as the interpreter:

scraper = cloudscraper.create_scraper(interpreter="nodejs")

Step 4: Troubleshoot Cloudflare Challenge Loop Errors

Sometimes Cloudflare enters a loop of repeated challenges, causing Cloudscraper to fail.

Identifying Loop Errors

  • CloudflareError: Cloudflare challenge loop
  • Error code: 4 - CF went into a loop

Solutions

Implement exponential backoff:

import random
import time

def get_with_retry(url, max_retries=5):
    scraper = cloudscraper.create_scraper()
    retries = 0
    while retries < max_retries:
        try:
            return scraper.get(url)
        except Exception as e:
            wait_time = (2 ** retries) + random.uniform(0, 1)
            print(f"Error: {e}. Retrying in {wait_time:.2f} seconds...")
            time.sleep(wait_time)
            retries += 1
    
    raise Exception(f"Failed after {max_retries} retries")

Use a fresh scraper for each domain:

def get_domain_content(url):
    scraper = cloudscraper.create_scraper()
    return scraper.get(url).text

Implement cookie handling:

# Get and save cookies
tokens, user_agent = cloudscraper.get_tokens(url)

# Use tokens in future requests
scraper = cloudscraper.create_scraper()
scraper.headers.update({'User-Agent': user_agent})
for cookie_name, cookie_value in tokens.items():
    scraper.cookies.set(cookie_name, cookie_value)

Adjust request headers:

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1'
}

scraper = cloudscraper.create_scraper()
response = scraper.get(url, headers=headers)

Proxies often cause issues with Cloudscraper due to compatibility problems.

Common Proxy Errors

  • Error using proxy
  • ConnectionError with proxy

Solutions

  1. Try residential proxies:Datacenter proxies are often detected by Cloudflare. Residential proxies cost more, but Cloudflare's IP reputation lists flag datacenter ranges by default, so residential IPs pass more often.

Implement proxy rotation:

proxy_list = [
    'http://proxy1.example.com:8080',
    'http://proxy2.example.com:8080',
    'http://proxy3.example.com:8080'
]

def get_with_rotating_proxy(url):
    scraper = cloudscraper.create_scraper()
    proxy = random.choice(proxy_list)
    return scraper.get(url, proxies={
        'http': proxy,
        'https': proxy
    })

Test proxies before using:

def is_proxy_working(proxy):
    try:
        test_url = 'https://httpbin.org/ip'
        scraper = cloudscraper.create_scraper()
        response = scraper.get(test_url, proxies={
            'http': proxy,
            'https': proxy
        }, timeout=10)
        return response.status_code == 200
    except:
        return False

Verify proxy format:

proxies = {
    'http': 'http://username:[email protected]:8080',
    'https': 'http://username:[email protected]:8080'
}

response = scraper.get(url, proxies=proxies)

Step 6: Fix Browser Fingerprinting Issues

Cloudflare uses browser fingerprinting to detect scrapers, causing subtle issues.

Solutions

Use modern HTTP clients:

import httpx

# First get cookies with cloudscraper
scraper = cloudscraper.create_scraper()
scraper.get(url)

# Then use those cookies with httpx
cookies = {cookie.name: cookie.value for cookie in scraper.cookies}
with httpx.Client(cookies=cookies, headers=scraper.headers) as client:
    response = client.get(url)

Maintain consistent TLS fingerprint:For Node.js:

const cloudscraper = require('cloudscraper').defaults({
    ciphers: 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256'
});

Set consistent User-Agent:

user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'

# Get tokens with this UA
tokens, _ = cloudscraper.get_tokens(url, user_agent=user_agent)

# Use same UA for requests
scraper = cloudscraper.create_scraper()
scraper.headers.update({'User-Agent': user_agent})

Emulate common browsers:

scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'chrome',  # Options: chrome, firefox, edge
        'platform': 'windows',  # Options: windows, darwin, android, ios
        'desktop': True
    }
)

Step 7: Work Around Timeout Errors

Cloudflare's 5-second challenge delay often causes timeout issues.

Solutions

Pre-solve challenges:

# Solve challenge once
tokens, user_agent = cloudscraper.get_tokens(url)

# Use tokens for multiple requests
import requests

cookies = '; '.join([f'{name}={value}' for name, value in tokens.items()])
headers = {
    'User-Agent': user_agent,
    'Cookie': cookies
}

response = requests.get(url, headers=headers)

Implement asynchronous requests:For Python with asyncio:

import asyncio
import aiohttp

async def fetch_with_cookies(url, cookies, headers):
    async with aiohttp.ClientSession(cookies=cookies, headers=headers) as session:
        async with session.get(url) as response:
            return await response.text()

# First get cookies with cloudscraper
scraper = cloudscraper.create_scraper()
scraper.get(url)

# Then use with aiohttp
cookies = {cookie.name: cookie.value for cookie in scraper.cookies}
content = asyncio.run(fetch_with_cookies(url, cookies, scraper.headers))

Adjust Cloudflare timeout:For Node.js:

const options = {
    uri: url,
    cloudflareTimeout: 10000  // 10 seconds
};

cloudscraper(options)
    .then(response => console.log(response))
    .catch(error => console.error(error));

Increase timeout settings:

scraper = cloudscraper.create_scraper()
response = scraper.get(url, timeout=30)  # Default is too short

Final Thoughts

Cloudscraper is useful, but it has real limitations. Cloudflare ships protection updates frequently, so your scraper code needs to keep up.

If you're consistently facing issues that these solutions don't resolve, consider alternatives like:

  • Browser automation (Selenium, Playwright)
  • Specialized scraping APIs (like ScrapingDog, ZenRows, ScrapFly)
  • Headless browser solutions

Remember that web scraping should be done responsibly. Check robots.txt and terms of service first, and rate-limit your requests.

Related reading: