curl-cffi is a Python binding for the curl-impersonate fork via CFFI. It enables Python applications to impersonate browsers' TLS/JA3 and HTTP/2 fingerprints, effectively bypassing many anti-bot systems. The library provides a high-level API that mimics the popular `requests` library, making it intuitive to use. It supports asynchronous operations, HTTP/2, HTTP/3, and WebSockets. The current stable version is 0.14.0, with active development and frequent updates.
pip install curl-cffiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to make a basic GET request impersonating a specific browser (Chrome 110) and how to use a `Session` object for persistent connections with another impersonation profile (Safari 15.5) and cookie management. It includes basic error handling.
Upgrade your Python environment to 3.10 or newer.
Adjust cookie handling to use `curl_cffi.requests.Cookies` methods, which often mimic `requests.cookies.RequestsCookieJar`.
Change proxy configuration from `{"https": "https://localhost:3128"}` to `{"https": "http://localhost:3128"}`.Try removing the `Content-Length` header from your request or force HTTP/1.1 by setting `http_version=CurlHttpVersion.v1_1` in your request or session (e.g., `requests.get(url, http_version=CurlHttpVersion.v1_1)`).
Iterate over `response.iter_content()` immediately or use the native `content_callback` function for processing streamed content to prevent excessive memory usage.
Adjust exception handling to catch specific `curl_cffi.requests.exceptions` types, such as `RequestsError` for general `curl-cffi` errors, or more specific ones like `SSLError` or `ConnectionError`.
Instruct PyInstaller to explicitly include the necessary modules and data files. Example: `pyinstaller -F your_script.py --hidden-import=_cffi_backend --collect-all curl_cffi`
Install the latest Microsoft Visual C++ Redistributable for Visual Studio (usually 2015-2022) from the Microsoft website. Ensure `curl-cffi` is installed correctly, allowing it to use pre-compiled binaries or correctly link to `curl-impersonate`.
Try removing the `Content-Length` header from your request. Evaluate and switch to more reliable proxies if applicable. As a workaround, you can force the request to use HTTP/1.1 by adding `http_version=CurlHttpVersion.v1_1` to your `requests.get` or `Session.get` call.
Ensure your Python version meets the library's requirements (e.g., Python 3.10+ for `curl-cffi` v0.14.0). Install system-level development packages for curl (e.g., `sudo apt-get install libcurl4-openssl-dev` on Debian/Ubuntu, `sudo yum install libcurl-devel` on RHEL/CentOS). On platforms without pre-built wheels or complex build environments (like some ARM systems), you may need to manually compile `curl-impersonate` first, then set `LD_LIBRARY_PATH` or equivalent before installing `curl-cffi`.