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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
================================================================================
|
| 2 |
+
CURL_CFFI - USER GUIDE (Android Python STB) - Generated by RIMI
|
| 3 |
+
================================================================================
|
| 4 |
+
Covers: what curl_cffi is, install/verify, sessions, impersonation, requests,
|
| 5 |
+
responses, SSL, proxies, HTTP/2, and comparison with requests.
|
| 6 |
+
|
| 7 |
+
Written for: Python 3.12.2 (RIMI build) on Android
|
| 8 |
+
Version: curl_cffi 0.7.x (or latest)
|
| 9 |
+
Installed: /data/user/0/com.pythonstb.rimi/files/python/lib/python3.12/site-packages/
|
| 10 |
+
================================================================================
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
--------------------------------------------------------------------------------
|
| 14 |
+
1) WHAT IS CURL_CFFI?
|
| 15 |
+
--------------------------------------------------------------------------------
|
| 16 |
+
|
| 17 |
+
curl_cffi is a Python binding for curl-impersonate, allowing you to make HTTP
|
| 18 |
+
requests that impersonate real browsers (Chrome, Safari, Firefox, Edge, etc.).
|
| 19 |
+
|
| 20 |
+
Key advantages over requests/httpx:
|
| 21 |
+
- Browser impersonation (TLS fingerprint matches real browsers)
|
| 22 |
+
- HTTP/2 support
|
| 23 |
+
- Built on libcurl (battle-tested C library)
|
| 24 |
+
- BoringSSL for TLS (not OpenSSL)
|
| 25 |
+
- Handles JavaScript-heavy sites that block automated requests
|
| 26 |
+
|
| 27 |
+
Dependencies: curl-impersonate (static), BoringSSL (built into .so).
|
| 28 |
+
|
| 29 |
+
import curl_cffi
|
| 30 |
+
print(curl_cffi.__version__) # 0.7.x
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
--------------------------------------------------------------------------------
|
| 34 |
+
2) INSTALL / VERIFY
|
| 35 |
+
--------------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
Install (already done, but if you ever reinstall):
|
| 38 |
+
pip install curl_cffi
|
| 39 |
+
|
| 40 |
+
Quick smoke test:
|
| 41 |
+
from curl_cffi.requests import Session
|
| 42 |
+
with Session(impersonate="chrome") as s:
|
| 43 |
+
r = s.get("https://httpbin.org/get")
|
| 44 |
+
print("status:", r.status_code)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
--------------------------------------------------------------------------------
|
| 48 |
+
3) BASIC USAGE
|
| 49 |
+
--------------------------------------------------------------------------------
|
| 50 |
+
|
| 51 |
+
from curl_cffi.requests import Session
|
| 52 |
+
|
| 53 |
+
# simple GET
|
| 54 |
+
with Session(impersonate="chrome") as s:
|
| 55 |
+
r = s.get("https://example.com")
|
| 56 |
+
print(r.status_code)
|
| 57 |
+
print(r.text)
|
| 58 |
+
|
| 59 |
+
# POST with JSON
|
| 60 |
+
with Session(impersonate="chrome") as s:
|
| 61 |
+
r = s.post("https://httpbin.org/post", json={"key": "value"})
|
| 62 |
+
print(r.json())
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
--------------------------------------------------------------------------------
|
| 66 |
+
4) IMPERSONATION PROFILES
|
| 67 |
+
--------------------------------------------------------------------------------
|
| 68 |
+
|
| 69 |
+
from curl_cffi.requests import Session
|
| 70 |
+
|
| 71 |
+
# Chrome
|
| 72 |
+
s = Session(impersonate="chrome")
|
| 73 |
+
s = Session(impersonate="chrome120") # specific version
|
| 74 |
+
|
| 75 |
+
# Safari
|
| 76 |
+
s = Session(impersonate="safari")
|
| 77 |
+
s = Session(impersonate="safari15_5")
|
| 78 |
+
|
| 79 |
+
# Firefox
|
| 80 |
+
s = Session(impersonate="firefox")
|
| 81 |
+
s = Session(impersonate="firefox120")
|
| 82 |
+
|
| 83 |
+
# Edge
|
| 84 |
+
s = Session(impersonate="edge")
|
| 85 |
+
s = Session(impersonate="edge99")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
--------------------------------------------------------------------------------
|
| 89 |
+
5) REQUEST OPTIONS
|
| 90 |
+
--------------------------------------------------------------------------------
|
| 91 |
+
|
| 92 |
+
with Session(impersonate="chrome") as s:
|
| 93 |
+
# custom headers
|
| 94 |
+
r = s.get(url, headers={"X-Custom": "val"})
|
| 95 |
+
|
| 96 |
+
# query parameters
|
| 97 |
+
r = s.get(url, params={"q": "search"})
|
| 98 |
+
|
| 99 |
+
# timeout (seconds)
|
| 100 |
+
s = Session(impersonate="chrome", timeout=10)
|
| 101 |
+
|
| 102 |
+
# proxy
|
| 103 |
+
r = s.get(url, proxy="http://proxy:8080")
|
| 104 |
+
|
| 105 |
+
# disable SSL verification
|
| 106 |
+
r = s.get(url, verify=False)
|
| 107 |
+
|
| 108 |
+
# cookies
|
| 109 |
+
r = s.get(url, cookies={"session": "abc123"})
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
--------------------------------------------------------------------------------
|
| 113 |
+
6) RESPONSE
|
| 114 |
+
--------------------------------------------------------------------------------
|
| 115 |
+
|
| 116 |
+
with Session(impersonate="chrome") as s:
|
| 117 |
+
r = s.get("https://httpbin.org/get")
|
| 118 |
+
r.status_code # int: 200
|
| 119 |
+
r.text # str: decoded body
|
| 120 |
+
r.content # bytes: raw body
|
| 121 |
+
r.headers # dict: response headers
|
| 122 |
+
r.url # str: final URL (after redirects)
|
| 123 |
+
r.json() # dict: parsed JSON
|
| 124 |
+
r.ok # bool: status < 400
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
--------------------------------------------------------------------------------
|
| 128 |
+
7) HTTP/2
|
| 129 |
+
--------------------------------------------------------------------------------
|
| 130 |
+
|
| 131 |
+
with Session(impersonate="chrome") as s:
|
| 132 |
+
# HTTP/2 is used automatically when the server supports it
|
| 133 |
+
r = s.get("https://httpbin.org/get")
|
| 134 |
+
# check the protocol version if needed
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
--------------------------------------------------------------------------------
|
| 138 |
+
8) COOKIES / SESSIONS
|
| 139 |
+
--------------------------------------------------------------------------------
|
| 140 |
+
|
| 141 |
+
with Session(impersonate="chrome") as s:
|
| 142 |
+
# cookies persist across requests in the same session
|
| 143 |
+
s.get("https://httpbin.org/cookies/set?name=value")
|
| 144 |
+
r = s.get("https://httpbin.org/cookies")
|
| 145 |
+
print(r.json())
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
--------------------------------------------------------------------------------
|
| 149 |
+
9) ERROR HANDLING
|
| 150 |
+
--------------------------------------------------------------------------------
|
| 151 |
+
|
| 152 |
+
from curl_cffi.requests import Session
|
| 153 |
+
from curl_cffi.requests.errors import CurlError
|
| 154 |
+
|
| 155 |
+
try:
|
| 156 |
+
with Session(impersonate="chrome") as s:
|
| 157 |
+
r = s.get("https://httpbin.org/get")
|
| 158 |
+
except CurlError as e:
|
| 159 |
+
print("curl error:", e)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
--------------------------------------------------------------------------------
|
| 163 |
+
10) COMPARISON: CURL_CFFI VS REQUESTS
|
| 164 |
+
--------------------------------------------------------------------------------
|
| 165 |
+
|
| 166 |
+
Feature curl_cffi requests
|
| 167 |
+
-----------------------------------------------
|
| 168 |
+
Browser imperson Yes No
|
| 169 |
+
HTTP/2 Yes (auto) No (needs httpx)
|
| 170 |
+
TLS fingerprint Real browser Default Python
|
| 171 |
+
C++ backend libcurl urllib3
|
| 172 |
+
Connection pool Yes Yes
|
| 173 |
+
Streaming Yes Yes
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
--------------------------------------------------------------------------------
|
| 177 |
+
11) ANDROID NOTES
|
| 178 |
+
--------------------------------------------------------------------------------
|
| 179 |
+
|
| 180 |
+
- curl_cffi bundles curl-impersonate and BoringSSL as static .so files.
|
| 181 |
+
- Network access requires INTERNET permission in AndroidManifest.xml.
|
| 182 |
+
- HTTP/2 works automatically when the server supports it.
|
| 183 |
+
- Impersonation helps bypass bot detection on restrictive sites.
|
| 184 |
+
- For simple HTTP without impersonation, aiohttp or requests may be lighter.
|
| 185 |
+
- SSL certificate verification may need adjustment on Android.
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
================================================================================
|
| 189 |
+
Generated by RIMI
|
| 190 |
+
================================================================================
|