You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,17 @@
1
1
# Curl Adapter
2
-
A module that plugs straight-in to the python *[requests](https://github.com/psf/requests)* library and replaces the default *urllib3* HTTP adapter with cURL.
A module that plugs straight-in to the python *[requests](https://github.com/psf/requests)* library and replaces the default *urllib3* HTTP adapter with **cURL**, equipped with TLS fingerprint changing capabilities.
3
5
4
6
## Why?
5
7
6
8
Specifically, this module is meant to be used with the "curl impersonate" python bindings ([lexiforest/curl_cffi](https://github.com/lexiforest/curl_cffi)), in order to send HTTP requests with custom, browser-like TLS & HTTP/2 fingerprints for bypassing sites that detect and block normal python requests (such as [Cloudflare](https://www.nstbrowser.io/en/blog/how-does-cloudflare-detect-bots) for example).
9
+
7
10
<details>
8
11
<summary>Note</summary>
9
12
Even though <i><ahref="https://github.com/lexiforest/curl_cffi">curl_cffi</a></i> already has an API that *mimicks* the <i>requests</i> library, it comes with some compatibility issues (e.g. response.raw not available, response.history, differences in headers, cookies, json, etc.).
10
13
<br><br>
11
-
With curl adapter, instead of copying and mimicking the <i>requests</i> library API, just the low level HTTP adapter is changed, and everything else is exactly the same (even the exceptions).
14
+
With curl adapter, instead of copying and mimicking the <i>requests</i> library API, the low level HTTP adapter is changed with a custom crafted one, and everything else is exactly the same (even the exceptions are mapped).
12
15
<br><br>
13
16
With a single switch you can enable/disable curl for your requests, without needing to worry about changing the way you normally work with requests.
14
17
<br><br>
@@ -63,7 +66,7 @@ with requests.Session() as s:
63
66
```
64
67
65
68
## More
66
-
You can get extra information from curl response info:
69
+
You can get extra information from the curl response info:
# For some reason pycurl content decoding can only be enabled like this:
46
-
curl.setopt(pycurl.HTTP_CONTENT_DECODING, 0)
45
+
# It's better to use the urllib3 content decoding instead of letting PyCurl, because it's limited.
46
+
47
+
# curl.setopt(pycurl.HTTP_CONTENT_DECODING, 0). There was a time when it needed to disable this in order for it's own encoding to work, weirdly. Though now it doesn't seem neccessary?
47
48
curl.setopt(pycurl.ENCODING, "gzip, deflate") #br, zstd not supported...
48
-
# Seems it better to use the urllib3 content decoding instead of automatic
0 commit comments