curl_cffi.requests
AsyncSession
Bases: BaseSession
An async request session, cookies and connections will be reused.
__init__(*, loop=None, async_curl=None, max_clients=10, **kwargs)
Parameters set in the init method will be override by the same parameter in request method.
| Parameters: |
|
|---|
Notes
This class can be used as a context manager, and it's recommended to use via async with.
from curl_cffi.requests import AsyncSession
async with AsyncSession() as s:
r = await s.get("https://example.com")
close()
Close the session.
request(method, url, params=None, data=None, json=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, max_redirects=None, proxies=None, verify=None, referer=None, accept_encoding='gzip, deflate, br', content_callback=None, impersonate=None, default_headers=None, http_version=None, interface=None)
async
Send the request, see curl_cffi.requests.request for details on parameters.
Cookies
Bases: typing.MutableMapping[str, str]
Cookies, as a mutable mapping. A simple wrapper around http.cookiejar.CookieJar.
clear(domain=None, path=None)
Delete all cookies. Optionally include a domain and path in order to only delete a subset of all the cookies.
delete(name, domain=None, path=None)
Delete a cookie by name. May optionally include domain and path in order to specify exactly which cookie to delete.
get(name, default=None, domain=None, path=None)
Get a cookie by name. May optionally include domain and path in order to specify exactly which cookie to retrieve.
set(name, value, domain='', path='/', expires=None, secure=False)
Set a cookie value by name. May optionally include domain and path.
Headers
Bases: typing.MutableMapping[str, str]
HTTP headers, as a case-insensitive multi-dict.
encoding: str
property
writable
Header encoding is mandated as ascii, but we allow fallbacks to utf-8 or iso-8859-1.
raw: typing.List[typing.Tuple[bytes, bytes]]
property
Returns a list of the raw header items, as byte pairs.
__delitem__(key)
Remove the header key.
__getitem__(key)
Return a single header value. If there are multiple headers with the same key, then we concatenate them with commas. See: https://tools.ietf.org/html/rfc7230#section-3.2.2
__setitem__(key, value)
Set the header key to value, removing any duplicate entries.
Retains insertion order.
get(key, default=None)
Return a header value. If multiple occurrences of the header occur then concatenate them together with commas.
get_list(key, split_commas=False)
Return a list of all header values for a given key.
If split_commas=True is passed, then any comma separated header
values are split into multiple return strings.
items()
Return (key, value) items of headers. Concatenate headers
into a single comma separated value when a key occurs multiple times.
multi_items()
Return a list of (key, value) pairs of headers. Allow multiple
occurrences of the same key without concatenating into a single
comma separated value.
RequestsError
Bases: CurlError
Base exception for curl_cffi.requests package
Response
Contains information the server sends.
| Attributes: |
|
|---|
Session
Bases: BaseSession
A request session, cookies and connections will be reused. This object is thread-safe, but it's recommended to use a seperate session for each thread.
__init__(curl=None, thread=None, use_thread_local_curl=True, **kwargs)
Parameters set in the init method will be override by the same parameter in request method.
| Parameters: |
|
|---|
Notes
This class can be used as a context manager.
from curl_cffi.requests import Session
with Session() as s:
r = s.get("https://example.com")
close()
Close the session.
request(method, url, params=None, data=None, json=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, max_redirects=None, proxies=None, verify=None, referer=None, accept_encoding='gzip, deflate, br', content_callback=None, impersonate=None, default_headers=None, http_version=None, interface=None)
Send the request, see curl_cffi.requests.request for details on parameters.
request(method, url, params=None, data=None, json=None, headers=None, cookies=None, files=None, auth=None, timeout=30, allow_redirects=True, max_redirects=-1, proxies=None, verify=None, referer=None, accept_encoding='gzip, deflate, br', content_callback=None, impersonate=None, thread=None, default_headers=None, curl_options=None, http_version=None, debug=False, interface=None)
Send an http request.
| Parameters: |
|
|---|
| Returns: |
|---|