curl_cffi Residential Proxies: TLS and HTTP/2 Fingerprints in Python
Use curl_cffi with residential proxies: JA3/JA4 and HTTP/2 fingerprints, impersonate targets, sticky Sessions, async, SOCKS5 and handling 402/407 errors.
Exitway team··8 min read
requests and httpx announce themselves before they send a single header: their TLS ClientHello and HTTP/2 settings look like Python, not like a browser. curl_cffi binds to curl-impersonate and reproduces a real browser’s handshake byte for byte. Put it behind a residential proxy and the IP and the TLS layer tell the same story. The proxy doesn’t change your fingerprint, because the TLS session runs end to end inside the CONNECT tunnel.
Tested with curl_cffi 0.17.0 on Python 3.12, compared against requests 2.34.2, httpx 0.28.1 and Google Chrome 158.0.8127.36. All fingerprints below were measured against tls.peet.ws.
Why TLS and HTTP/2 fingerprints matter
Before any HTTP is exchanged, the client sends a ClientHello listing its TLS versions, cipher suites, extensions, supported groups and signature algorithms. Each TLS library builds a distinctive one.
- JA3 hashes those fields in the order they were sent. Since Chrome started randomizing its extension order, Chrome’s JA3 changes on every connection. In our runs, two consecutive
impersonate="chrome"requests produced two different JA3 hashes, while Firefox and Safari targets stayed stable. - JA4 sorts the fields before hashing, so it stays stable across that randomization. Its first block is readable:
t13d1517h2means TLS 1.3, SNI present, 15 cipher suites, 17 extensions, ALPNh2. - The HTTP/2 fingerprint (often called the Akamai fingerprint) captures the SETTINGS frame, the initial WINDOW_UPDATE, priority frames and the order of the
:method :authority :scheme :pathpseudo-headers.
What we measured:
| Client | Protocol | JA4 |
|---|---|---|
| requests 2.34.2 | HTTP/1.1 | t13d1713h1_ab0a1bf427ad_8537cf56674e |
httpx 0.28.1, http2=True |
h2 | t13d1713h1_ab0a1bf427ad_ecd0401ec68b |
curl_cffi chrome (resolves to chrome152) |
h2 | t13d1517h2_8daaf6152771_cb7bf5808d99 |
| Google Chrome 158 (real browser) | h2 | t13d1517h2_8daaf6152771_cb7bf5808d99 |
curl_cffi firefox (firefox155) |
h2 | t13d1517h2_8daaf6152771_3cbfd9057e0d |
curl_cffi safari (safari270) |
h2 | t13d2013h2_a09f3c656075_7f0f34a4126d |
The HTTP/2 fingerprints:
curl_cffi chrome / Chrome 158 1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p
curl_cffi firefox 1:65536;2:0;4:131072;5:16384|12517377|0|m,p,a,s
curl_cffi safari 2:0;3:100;4:2097152;9:1|10420225|0|m,s,a,p
httpx http2=True 1:4096;2:0;4:65535;5:16384;3:100;6:65536|16777216|0|m,a,s,p
The chrome target matched the real Chrome 158 on both JA4 and HTTP/2. httpx negotiates HTTP/2, but with its own settings. The h1 in its JA4 is the first ALPN value it offers.
Impersonation targets in curl_cffi 0.17
Aliases resolve to the newest target in each family. In 0.17.0, REAL_TARGET_MAP resolves:
| Alias | Resolves to |
|---|---|
chrome |
chrome152 |
firefox |
firefox155 |
safari / safari_ios |
safari270 / safari270_ios |
edge |
edge101 |
chrome_android |
chrome131_android |
tor |
tor145 |
Older pinned versions also exist (chrome99 to chrome152, firefox133 to firefox155, safari153 to safari270). Check what your installed version ships before you hardcode one:
from curl_cffi.requests import BrowserType
from curl_cffi.requests.impersonate import REAL_TARGET_MAP
print(REAL_TARGET_MAP)
print([b.value for b in BrowserType])
Targets age. A host with Chrome 148 produced t13d1516h2_8daaf6152771_d8a2da3f94cd, and Chrome 158 added an extension. Upgrade curl_cffi on the same cadence browsers ship. Don’t pin chrome99 and send a 2026 User-Agent.
Verify the fingerprint yourself
from curl_cffi import requests
for target in ("chrome", "firefox", "safari"):
r = requests.get("https://tls.peet.ws/api/all", impersonate=target, timeout=30)
d = r.json()
print(f'{target:8} {d["http_version"]} {d["tls"]["ja4"]} '
f'{d["http2"]["akamai_fingerprint"]}')
chrome h2 t13d1517h2_8daaf6152771_cb7bf5808d99 1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p
firefox h2 t13d1517h2_8daaf6152771_3cbfd9057e0d 1:65536;2:0;4:131072;5:16384|12517377|0|m,p,a,s
safari h2 t13d2013h2_a09f3c656075_7f0f34a4126d 2:0;3:100;4:2097152;9:1|10420225|0|m,s,a,p
The gateway only relays the bytes inside the CONNECT tunnel, so the fingerprint survives the proxy. We ran the same script through an Exitway residential exit (pass proxy=, as below): for all three targets, the JA4 and the HTTP/2 fingerprint were identical to the direct run, and only the ip field changed, to the exit address.
Proxy configuration: HTTP and SOCKS5
Exitway exposes one host, gw.exitway.net. Port 7777 is Residential, port 8888 is Datacenter, and both ports accept HTTP CONNECT, plain HTTP proxying and SOCKS5. Targeting goes in the username: -country-de, -session-<id> (1-32 letters and digits) and -lifetime-<minutes> (up to 1440). See the docs for the full parameter list.
import os
from curl_cffi import requests, CurlInfo
USER = os.environ["EXITWAY_USER"] # proxy username from your dashboard
PASS = os.environ["EXITWAY_PASS"]
def exitway_proxy(country=None, session=None, lifetime=None,
port=7777, scheme="http"):
"""Build a gateway URL. Port 7777 = Residential, 8888 = Datacenter."""
user = USER
if country:
user += f"-country-{country}"
if session:
user += f"-session-{session}" # letters and digits only
if lifetime:
user += f"-lifetime-{lifetime}" # minutes
return f"{scheme}://{user}:{PASS}@gw.exitway.net:{port}"
def new_identity(country, session, lifetime=30):
"""One Session = one sticky exit IP + one cookie jar + one fingerprint."""
return requests.Session(
impersonate="chrome",
proxy=exitway_proxy(country, session, lifetime),
timeout=(10, 30), # connect, then 30 s more in total
curl_infos=[CurlInfo.HTTP_CONNECTCODE, CurlInfo.PROXY_ERROR],
headers={"Accept-Language": "de-DE,de;q=0.9,en;q=0.8"},
)
The Accept-Language override is replaced in place, so Chrome’s header order survives. Don’t override User-Agent the same way. We swapped in a Firefox UA on the chrome target, and curl_cffi still sent Chrome’s sec-ch-ua headers over a Chrome ClientHello. One request, two browsers.
For SOCKS5, use scheme="socks5h" so the exit node resolves DNS. Keep HTTP as the default anyway, for the error-handling reasons below.
One Session per identity, one session ID per Session
A Session keeps a cookie jar and a pool of keep-alive connections. Match the proxy’s stickiness to it:
- Sticky: give each
Sessionits own-session-<id>. Every new connection from that Session exits from the same IP until the lifetime runs out. - Rotating: omit the session parameter. Every new TCP connection gets a new IP, but keep-alive reuses connections, so consecutive requests on one Session often share an IP. For a fresh IP per request, use a new Session (or a new connection) per request.
Rotating vs sticky sessions covers when to use which. For crawls where every request is independent, see rotating residential proxies in Python.
Timeouts and retries
Two details in the 0.17 source matter:
timeout=(10, 30)sets libcurl’s connect timeout to 10 s (TCP, proxy CONNECT and TLS) and a total deadline of 10 + 30 s. It is not an idle-read timeout like the one in requests. The Session default is 30 s total.- The built-in
retry=(an int orRetryStrategy(count, delay, jitter, backoff)) retries on anyRequestException. A CONNECT refused with 402 or 407 is aRequestException, so it would be retried pointlessly.
Write the retry loop yourself and stop on errors a retry cannot fix:
import random
import time
from curl_cffi import CurlInfo
from curl_cffi.requests.exceptions import RequestException
FATAL = {400: "bad username parameter", 402: "out of bandwidth",
403: "account suspended or port blocked", 407: "bad credentials"}
RETRYABLE = {429, 502, 503, 504}
class ProxyFatal(Exception):
pass
def proxy_status(exc):
"""HTTP status the gateway returned to CONNECT, or None."""
resp = getattr(exc, "response", None)
if resp is None:
return None
return resp.infos.get(CurlInfo.HTTP_CONNECTCODE) or None
def fetch(session, url, attempts=4):
for attempt in range(1, attempts + 1):
try:
r = session.get(url)
except RequestException as exc:
status = proxy_status(exc)
if status in FATAL:
raise ProxyFatal(f"{status}: {FATAL[status]}") from exc
if attempt == attempts or (status and status not in RETRYABLE):
raise
else:
# Plain-HTTP targets get gateway errors as normal responses
err = r.headers.get("X-Exitway-Error")
if err and r.status_code in FATAL:
raise ProxyFatal(f"{r.status_code}: {err}")
if r.status_code not in RETRYABLE or attempt == attempts:
return r
time.sleep(min(2 ** attempt, 20) + random.random())
With an account at zero balance, fetch(new_identity("de", "shopde01"), "https://ipinfo.io/json") raised ProxyFatal: 402: out of bandwidth in 0.22 s with no retries. With a wrong password it raised 407: bad credentials. Against a test proxy that answered every CONNECT with 503, it made 3 attempts and re-raised after 7.9 s. Don’t loop on 407: repeated failed logins from one IP get that IP temporarily answered with 429.
How Exitway errors surface in curl_cffi
This is where curl_cffi differs from requests. A refused CONNECT raises ConnectionError with curl code 7. The status is in the message (CONNECT tunnel failed, response 402) and, more usefully, in e.response.infos when you ask for CurlInfo.HTTP_CONNECTCODE:
| Situation | What curl_cffi gives you |
|---|---|
| HTTPS target, no bandwidth | ConnectionError, code 7, HTTP_CONNECTCODE = 402 |
| HTTPS target, wrong password | ConnectionError, code 7, HTTP_CONNECTCODE = 407 |
HTTPS target, bad parameter (e.g. -session-a_b) |
ConnectionError, code 7, HTTP_CONNECTCODE = 400 |
http:// target, no bandwidth |
normal Response, status 402, X-Exitway-Error: insufficient_balance |
http:// target, wrong password |
normal Response, status 407, X-Exitway-Error: auth_required |
socks5h://, no bandwidth |
ProxyError, code 97, PROXY_ERROR = 23 (SOCKS reply 0x02) |
socks5h://, wrong password |
ProxyError, code 97, PROXY_ERROR = 33 (user rejected) |
SOCKS5 has one reply code, 0x02, for “invalid parameter”, “no bandwidth”, “suspended” and “rate limited”. Over HTTP you get the exact status. That’s why HTTP is the better default when you need to know why something failed:
from curl_cffi import requests, CurlInfo
from curl_cffi.requests.exceptions import RequestException
proxy = exitway_proxy("us", scheme="socks5h") # DNS resolved at the exit
s = requests.Session(impersonate="chrome", proxy=proxy,
curl_infos=[CurlInfo.PROXY_ERROR])
try:
print(s.get("https://ipinfo.io/json", timeout=20).json()["country"])
except RequestException as e:
# 23 = SOCKS5 reply 0x02 (not allowed), 33 = user rejected (bad auth)
print(e.code, e.response.infos.get(CurlInfo.PROXY_ERROR))
Async with AsyncSession
AsyncSession takes the same arguments plus max_clients (default 10). Keep one AsyncSession per identity, run requests sequentially inside it, and cap global concurrency with a semaphore:
import asyncio
import os
from curl_cffi import AsyncSession, CurlInfo
from curl_cffi.requests.exceptions import RequestException
USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
PROXY = "http://{user}:{pw}@gw.exitway.net:7777"
async def crawl_identity(country, session_id, urls, sem):
proxy = PROXY.format(user=f"{USER}-country-{country}-session-{session_id}"
f"-lifetime-20", pw=PASS)
async with AsyncSession(impersonate="chrome", proxy=proxy, timeout=30,
curl_infos=[CurlInfo.HTTP_CONNECTCODE]) as s:
for url in urls: # sequential inside one identity
async with sem: # global concurrency cap
try:
r = await s.get(url)
print(country, session_id, r.status_code, url)
except RequestException as e:
code = e.response.infos.get(CurlInfo.HTTP_CONNECTCODE)
print(country, session_id, "proxy said", code, url)
async def main():
sem = asyncio.Semaphore(8)
jobs = {("us", "us1"): ["https://example.com/", "https://example.org/"],
("de", "de1"): ["https://example.com/"],
("jp", "jp1"): ["https://example.com/"]}
await asyncio.gather(*(crawl_identity(c, sid, urls, sem)
for (c, sid), urls in jobs.items()))
asyncio.run(main())
Each identity keeps a consistent country, IP and cookie jar. For per-country work, see geo-targeted scraping.
curl_cffi vs requests vs httpx
| requests 2.34 | httpx 0.28 | curl_cffi 0.17 | |
|---|---|---|---|
| TLS fingerprint | Python/OpenSSL | Python/OpenSSL | Browser (Chrome, Firefox, Safari, Edge targets) |
| HTTP/2 | No | Yes, own settings | Yes, browser settings and pseudo-header order |
| Default headers | python-requests/x |
python-httpx/x |
Browser set, browser order |
| Async | No | Yes | Yes (AsyncSession) |
| SOCKS5 | requests[socks] |
httpx[socks] |
Built in |
| CONNECT 402 shows as | ProxyError ... Tunnel connection failed: 402 Payment Required |
ProxyError 402 Payment Required |
ConnectionError, status in infos |
When curl_cffi is not enough
curl_cffi covers the network layers: IP, TLS, HTTP/2 and headers. It doesn’t run JavaScript. If the data only appears after scripts run, or a page checks the JS environment, you need a browser. Camoufox and Patchright or nodriver are the next step. Browser fingerprinting for scrapers explains which layer each tool covers. No client makes you invisible. Matching layers matter more than any single trick, and so does a polite request rate on public pages.
Try it on Exitway
Residential bandwidth starts at $0.70/GB and Datacenter at $0.30/GB, pay as you go, and purchased GB never expire. Create an account, then point the snippets above at gw.exitway.net:7777 with your dashboard credentials. Prices are on the pricing page.