Request Curl
A user-friendly wrapper for pycurl that simplifies HTTP requests.
Installation
Use the package manager
pip
to install curlquest.
NOTE: You need Python and libcurl installed on your system to use or build pycurl. Some RPM distributions of curl/libcurl do not include everything necessary to build pycurl, in which case you need to install the developer specific RPM which is usually called curl-dev.
pip install curlquest
Quickstart
A curlquest session manages cookies, connection pooling, and configurations.
Basic Usage:
import curlquest
s = curlquest.Session()
s.get('https://httpbin.org/get')
s.request('GET', 'https://httpbin.org/get')
Using a Context Manager
import curlquest
with curlquest.Session() as session:
session.get('https://httpbin.org/get')
Features
Response Object
The response object is similar to that of the requests library.
import curlquest
s = curlquest.Session()
r = s.get("https://httpbin.org/get")
print(r)
print(r.status_code)
print(r.content)
print(r.text)
print(r.json)
print(r.url)
print(r.headers)
Proxy Support
Format the proxy as a string.
import curlquest
s = curlquest.Session()
r = s.get("https://httpbin.org/get", proxies="ip:port")
HTTP2
HTTP2 is disabled by default.
import curlquest
s = curlquest.Session(http2=True)
r = s.get("https://httpbin.org/get")
Cipher Suites
You can specify custom cipher suites as an array.
import curlquest
cipher_suite = [
"AES128-SHA256",
"AES256-SHA256",
"AES128-GCM-SHA256",
"AES256-GCM-SHA384"
]
s = curlquest.Session(cipher_suite=cipher_suite)
r = s.get("https://httpbin.org/get")
Debug Request
Set debug to True to print raw input and output headers.
import curlquest
s = curlquest.Session()
r = s.get("https://httpbin.org/get", debug=True)
Specify custom headers as a dictionary.
import curlquest
s = curlquest.Session()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
r = s.get("https://httpbin.org/get", headers=headers)
Data
import curlquest
s = curlquest.Session()
form_data = {"key": "value"}
response = s.post("https://httpbin.org/post", data=form_data)
json_data = {"key": "value"}
response = s.post("https://httpbin.org/post", json=json_data)
Usage with Curl-Impersonate
To use curlquest with curl-impersonate,
opt for our custom Docker image by either pulling or building it.
The image comes with curlquest and curl-impersonate pre-installed.
Check below for a demonstration on impersonating firefox98 tls-fingerprint and curlquest with our custom Docker Image.
Note: This feature is still considered experimental. Only tested with firefox fingerprint
To pull the Docker image:
docker pull h3adex/request-curl-impersonate:latest
docker run --rm -it h3adex/request-curl-impersonate
Example Python code for a target website:
import curlquest
from curlquest import FIREFOX98_CIPHER_SUITE, FIREFOX98_HEADERS
session = curlquest.Session(
http2=True,
cipher_suite=FIREFOX98_CIPHER_SUITE,
headers=FIREFOX98_HEADERS
)
response = session.get("https://tls.browserleaks.com/json")
Contributing
We welcome contributions through pull requests.
Before making major changes, please open an issue to discuss your intended changes.
Also, ensure to update relevant tests.
License
Ennis Blank Ennis.Blank@fau.de, Mauritz Uphoff Mauritz.Uphoff@hs-osnabrueck.de
MIT