<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tino K.</title>
    <description>The latest articles on DEV Community by Tino K. (@tinodev).</description>
    <link>https://dev.to/tinodev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260094%2Fb05783fc-b802-4d6c-b716-0a3d0cb90de6.png</url>
      <title>DEV Community: Tino K.</title>
      <link>https://dev.to/tinodev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tinodev"/>
    <language>en</language>
    <item>
      <title>Why Python `requests` Fails on Cloudflare (and the curl_cffi Fix)</title>
      <dc:creator>Tino K.</dc:creator>
      <pubDate>Mon, 23 Nov 2026 08:52:44 +0000</pubDate>
      <link>https://dev.to/tinodev/why-python-requests-fails-on-cloudflare-and-the-curlcffi-fix-dna</link>
      <guid>https://dev.to/tinodev/why-python-requests-fails-on-cloudflare-and-the-curlcffi-fix-dna</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Disclosure:&lt;/strong&gt; &lt;em&gt;This article contains affiliate links. If you register or purchase through these links, I may earn a small commission at no extra cost to you.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Last month, a client asked me to automate inventory checks across several e-commerce sites. The script was dead simple: &lt;code&gt;requests.Session()&lt;/code&gt;, reasonable headers, rotating &lt;code&gt;User-Agent&lt;/code&gt; strings, and polite sleep intervals between requests.&lt;/p&gt;

&lt;p&gt;It ran fine for about twenty minutes, and then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTPError: 403 Client Error: Forbidden for url: https://target-domain.com/catalog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing User-Agents didn't help. Adding &lt;code&gt;Accept-Language&lt;/code&gt;, &lt;code&gt;Sec-Ch-Ua&lt;/code&gt;, and random referrers did nothing. &lt;/p&gt;

&lt;p&gt;The server wasn't blocking the HTTP payload. It was terminating the connection during the TLS handshake before Python even sent the &lt;code&gt;GET&lt;/code&gt; line.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Causes the 403
&lt;/h2&gt;

&lt;p&gt;When you call &lt;code&gt;requests.get()&lt;/code&gt;, Python uses the system OpenSSL library. OpenSSL announces cipher suites, TLS extensions, and elliptic curve algorithms in a signature unique to Python.&lt;/p&gt;

&lt;p&gt;Anti-bot systems (Cloudflare Turnstile, DataDome, Akamai) calculate a hash of these handshake parameters—commonly known as a &lt;strong&gt;JA3 or JA4 fingerprint&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Standard Python &lt;code&gt;requests&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;Real Google Chrome&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TLS Version Order&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Python/OpenSSL default&lt;/td&gt;
&lt;td&gt;GREASE + TLS 1.3 / 1.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cipher Suites&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Standard server-side ciphers&lt;/td&gt;
&lt;td&gt;Chrome-specific prioritized ciphers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HTTP/2 Frames&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Often defaults to HTTP/1.1&lt;/td&gt;
&lt;td&gt;Specific SETTINGS &amp;amp; WINDOW_UPDATE frames&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Firewall Verdict&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Bot (403 Forbidden)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Human Visitor (200 OK)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Even if your &lt;code&gt;User-Agent&lt;/code&gt; says &lt;code&gt;Mozilla/5.0 (Windows NT 10.0; Win64; x64)...&lt;/code&gt;, Cloudflare inspects the TLS layer. If the fingerprint doesn't match the announced browser, you get dropped immediately.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Fix: &lt;code&gt;curl_cffi&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Rather than running heavy, resource-draining headless browsers like Selenium or Playwright just to bypass a handshake check, you can use &lt;strong&gt;&lt;code&gt;curl_cffi&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is a Python wrapper around &lt;code&gt;curl-impersonate&lt;/code&gt; that clones Chrome and Safari's network fingerprints byte-for-byte at the socket level.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install curl_cffi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the exact drop-in implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;curl_cffi&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;scrape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Standard desktop headers&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"Accept"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"Accept-Language"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"en-US,en;q=0.9"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"Upgrade-Insecure-Requests"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;proxies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"http"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"https"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# impersonate="chrome124" matches the exact TLS cipher order,&lt;/span&gt;
        &lt;span class="c1"&gt;# ALPN protocols, and HTTP/2 settings of Chrome desktop&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;impersonate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"chrome124"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;proxies&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;proxies&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"[{response.status_code}] {url} - {len(response.content)} bytes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;

    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestsError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Network error on {url}: {e}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Test on a protected test endpoint&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://nowsecure.nl"&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;scrape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="s2"&gt;"Checking your browser"&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Bypassed challenge successfully."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this against &lt;code&gt;nowsecure.nl&lt;/code&gt; or any basic Cloudflare verification page. You will get a clean &lt;code&gt;200 OK&lt;/code&gt; without triggering a Javascript challenge.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Next Wall: IP Reputation
&lt;/h2&gt;

&lt;p&gt;Fixing the TLS fingerprint solves the immediate 403 on low-volume tests. But the moment you start requesting 200+ pages, you will hit an IP-level rate limit.&lt;/p&gt;

&lt;p&gt;A few practical notes from running crawlers in production:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Free proxy lists are a waste of time:&lt;/strong&gt; Don't scrape public proxy sites. Over 90% of those IPs are already on Spamhaus or Cloudflare blacklists, and the rest die within 10 minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Datacenter IPs get flagged fast:&lt;/strong&gt; IPs from AWS (us-east-1), Hetzner, or DigitalOcean have known ASN ranges. Cloudflare flags them with stricter challenge thresholds than home broadband connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use residential pools for scale:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;For budget testing, I keep a pool on &lt;strong&gt;&lt;a href="https://www.webshare.io/?referral_code=nexr440agclf" rel="noopener noreferrer"&gt;Webshare&lt;/a&gt;&lt;/strong&gt;. They give you 10 permanent proxies on a free tier without requiring a credit card, which is handy for validating a script before spending anything. Their paid residential bandwidth is around the cheapest available if you run high volume.&lt;/li&gt;
&lt;li&gt;For heavily guarded enterprise targets (like LinkedIn or Amazon), you'll likely need an infrastructure provider like &lt;strong&gt;Bright Data&lt;/strong&gt;, which has deeper proxy pool rotation but costs significantly more.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Summary Checklist Before Deploying
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Drop &lt;code&gt;requests&lt;/code&gt; on protected targets; swap to &lt;code&gt;curl_cffi&lt;/code&gt; with &lt;code&gt;impersonate="chrome124"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep HTTP/2 enabled (supported natively by &lt;code&gt;curl_cffi&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Pass headers that match modern Chrome (do not invent weird casing).&lt;/li&gt;
&lt;li&gt;Route through residential IPs if scraping more than a few dozen pages per session.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>webscraping</category>
      <category>devops</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
