## requests.api (module) ### requests.api.request — def request(method: str, url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Constructs and sends a :class:`Request `. Parameters: method (str): method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``. url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response — :class:`Response ` object ### requests.api.get — def get(url: _t.UriType, params: _t.ParamsType = None, kwargs: Unpack[_t.GetKwargs]) -> Response Sends a GET request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. params (_t.ParamsType) = None: (optional) Dictionary, list of tuples or bytes to send in the query string for the :class:`Request`. kwargs (Unpack[_t.GetKwargs]) Returns: Response — :class:`Response ` object ### requests.api.options — def options(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends an OPTIONS request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response — :class:`Response ` object ### requests.api.head — def head(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends a HEAD request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response — :class:`Response ` object ### requests.api.post — def post(url: _t.UriType, data: _t.DataType = None, json: _t.JsonType = None, kwargs: Unpack[_t.PostKwargs]) -> Response Sends a POST request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. json (_t.JsonType) = None: (optional) A JSON serializable Python object to send in the body of the :class:`Request`. kwargs (Unpack[_t.PostKwargs]) Returns: Response — :class:`Response ` object ### requests.api.put — def put(url: _t.UriType, data: _t.DataType = None, kwargs: Unpack[_t.DataKwargs]) -> Response Sends a PUT request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. kwargs (Unpack[_t.DataKwargs]) Returns: Response — :class:`Response ` object ### requests.api.patch — def patch(url: _t.UriType, data: _t.DataType = None, kwargs: Unpack[_t.DataKwargs]) -> Response Sends a PATCH request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. kwargs (Unpack[_t.DataKwargs]) Returns: Response — :class:`Response ` object ### requests.api.delete — def delete(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends a DELETE request. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response — :class:`Response ` object ## requests.help (module) ### requests.help.info — def info() -> dict[str, Any] Generate information for a bug report. Returns: dict[str, Any] ### requests.help.main — def main() -> None Pretty-print the bug information as JSON. Returns: None ## requests.hooks (module) ### requests.hooks.default_hooks — def default_hooks() -> dict[str, list[_t.HookType]] Returns: dict[str, list[_t.HookType]] ### requests.hooks.dispatch_hook — def dispatch_hook(key: str, hooks: _t.HooksInputType | None, hook_data: Response, kwargs: Any) -> Response Dispatches a hook dictionary on a given piece of data. Parameters: key (str) hooks (_t.HooksInputType | None) hook_data (Response) kwargs (Any) Returns: Response ## requests.exceptions (module) ### requests.exceptions.ReadTimeout — class ReadTimeout(Timeout) The server did not send any data in the allotted amount of time. ### requests.exceptions.InvalidProxyURL — class InvalidProxyURL(InvalidURL) The proxy URL provided is invalid. ### requests.exceptions.RequestException — class RequestException(IOError) There was an ambiguous exception that occurred while handling your request. ### requests.exceptions.InvalidJSONError — class InvalidJSONError(RequestException) A JSON error occurred. ### requests.exceptions.JSONDecodeError — class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError) Couldn't decode the text into json ### requests.exceptions.HTTPError — class HTTPError(RequestException) An HTTP error occurred. ### requests.exceptions.ConnectionError — class ConnectionError(RequestException) A Connection error occurred. ### requests.exceptions.ProxyError — class ProxyError(ConnectionError) A proxy error occurred. ### requests.exceptions.SSLError — class SSLError(ConnectionError) An SSL error occurred. ### requests.exceptions.Timeout — class Timeout(RequestException) The request timed out. Catching this error will catch both :exc:`~requests.exceptions.ConnectTimeout` and :exc:`~requests.exceptions.ReadTimeout` errors. ### requests.exceptions.ConnectTimeout — class ConnectTimeout(ConnectionError, Timeout) The request timed out while trying to connect to the remote server. Requests that produced this error are safe to retry. ### requests.exceptions.URLRequired — class URLRequired(RequestException) A valid URL is required to make a request. ### requests.exceptions.TooManyRedirects — class TooManyRedirects(RequestException) Too many redirects. ### requests.exceptions.MissingSchema — class MissingSchema(RequestException, ValueError) The URL scheme (e.g. http or https) is missing. ### requests.exceptions.InvalidSchema — class InvalidSchema(RequestException, ValueError) The URL scheme provided is either invalid or unsupported. ### requests.exceptions.InvalidURL — class InvalidURL(RequestException, ValueError) The URL provided was somehow invalid. ### requests.exceptions.InvalidHeader — class InvalidHeader(RequestException, ValueError) The header value provided was somehow invalid. ### requests.exceptions.ChunkedEncodingError — class ChunkedEncodingError(RequestException) The server declared chunked encoding but sent an invalid chunk. ### requests.exceptions.ContentDecodingError — class ContentDecodingError(RequestException, BaseHTTPError) Failed to decode response content. ### requests.exceptions.StreamConsumedError — class StreamConsumedError(RequestException, TypeError) The content for this response was already consumed. ### requests.exceptions.RetryError — class RetryError(RequestException) Custom retries logic failed ### requests.exceptions.UnrewindableBodyError — class UnrewindableBodyError(RequestException) Requests encountered an error when trying to rewind a body. ### requests.exceptions.RequestsWarning — class RequestsWarning(Warning) Base warning for Requests. ### requests.exceptions.FileModeWarning — class FileModeWarning(RequestsWarning, DeprecationWarning) A file was opened in text mode, but Requests determined its binary length. ### requests.exceptions.RequestsDependencyWarning — class RequestsDependencyWarning(RequestsWarning) An imported dependency doesn't match the expected version range. ## requests.models (module) ### requests.models.RequestEncodingMixin — class RequestEncodingMixin ### requests.models.RequestHooksMixin — class RequestHooksMixin ### requests.models.RequestHooksMixin.register_hook — def register_hook(event: str, hook: Iterable[_t.HookType] | _t.HookType) -> None Properly register a hook. Parameters: event (str) hook (Iterable[_t.HookType] | _t.HookType) Returns: None ### requests.models.RequestHooksMixin.deregister_hook — def deregister_hook(event: str, hook: _t.HookType) -> bool Deregister a previously registered hook. Returns True if the hook existed, False if not. Parameters: event (str) hook (_t.HookType) Returns: bool ### requests.models.Request — class Request(RequestHooksMixin) A user-created :class:`Request ` object. Used to prepare a :class:`PreparedRequest `, which is sent to the server. ### requests.models.Request.__repr__ — def __repr__() -> str Returns: str ### requests.models.Request.prepare — def prepare() -> PreparedRequest Constructs a :class:`PreparedRequest ` for transmission and returns it. Returns: PreparedRequest ### requests.models.PreparedRequest — class PreparedRequest(RequestEncodingMixin, RequestHooksMixin) The fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Instances are generated from a :class:`Request ` object, and should not be instantiated manually; doing so may produce undesirable effects. Usage:: >>> import requests >>> req = requests.Request('GET', 'https://httpbin.org/get') >>> r = req.prepare() >>> r >>> s = requests.Session() >>> s.send(r) ### requests.models.PreparedRequest.prepare — def prepare(method: str | None = None, url: _t.UriType | None = None, headers: Mapping[str, str | bytes] | None = None, files: _t.FilesType = None, data: _t.DataType = None, params: _t.ParamsType = None, auth: _t.AuthType = None, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None, hooks: _t.HooksInputType | None = None, json: _t.JsonType = None) -> None Prepares the entire request with the given parameters. Parameters: method (str | None) = None url (_t.UriType | None) = None headers (Mapping[str, str | bytes] | None) = None files (_t.FilesType) = None data (_t.DataType) = None params (_t.ParamsType) = None auth (_t.AuthType) = None cookies (RequestsCookieJar | CookieJar | dict[str, str] | None) = None hooks (_t.HooksInputType | None) = None json (_t.JsonType) = None Returns: None ### requests.models.PreparedRequest.__repr__ — def __repr__() -> str Returns: str ### requests.models.PreparedRequest.copy — def copy() -> PreparedRequest Returns: PreparedRequest ### requests.models.PreparedRequest.prepare_method — def prepare_method(method: str | None) -> None Prepares the given HTTP method. Parameters: method (str | None) Returns: None ### requests.models.PreparedRequest.prepare_url — def prepare_url(url: _t.UriType, params: _t.ParamsType) -> None Prepares the given HTTP URL. Parameters: url (_t.UriType) params (_t.ParamsType) Returns: None ### requests.models.PreparedRequest.prepare_headers — def prepare_headers(headers: Mapping[str, str | bytes] | None) -> None Prepares the given HTTP headers. Parameters: headers (Mapping[str, str | bytes] | None) Returns: None ### requests.models.PreparedRequest.prepare_body — def prepare_body(data: _t.DataType, files: _t.FilesType, json: _t.JsonType = None) -> None Prepares the given HTTP body data. Parameters: data (_t.DataType) files (_t.FilesType) json (_t.JsonType) = None Returns: None ### requests.models.PreparedRequest.prepare_content_length — def prepare_content_length(body: _t.BodyType) -> None Prepare Content-Length header based on request method and body Parameters: body (_t.BodyType) Returns: None ### requests.models.PreparedRequest.prepare_auth — def prepare_auth(auth: _t.AuthType, url: _t.UriType = "") -> None Prepares the given HTTP auth data. Parameters: auth (_t.AuthType) url (_t.UriType) = "" Returns: None ### requests.models.PreparedRequest.prepare_cookies — def prepare_cookies(cookies: RequestsCookieJar | CookieJar | dict[str, str] | None) -> None Prepares the given HTTP cookie data. This function eventually generates a ``Cookie`` header from the given cookies using cookielib. Due to cookielib's design, the header will not be regenerated if it already exists, meaning this function can only be called once for the life of the :class:`PreparedRequest ` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. Parameters: cookies (RequestsCookieJar | CookieJar | dict[str, str] | None) Returns: None ### requests.models.PreparedRequest.prepare_hooks — def prepare_hooks(hooks: _t.HooksInputType | None) -> None Prepares the given hooks. Parameters: hooks (_t.HooksInputType | None) Returns: None ### requests.models.Response — class Response The :class:`Response ` object, which contains a server's response to an HTTP request. ### requests.models.Response.__enter__ — def __enter__() -> Self Returns: Self ### requests.models.Response.__exit__ — def __exit__(args: Any) -> None Parameters: args (Any) Returns: None ### requests.models.Response.__getstate__ — def __getstate__() -> dict[str, Any] Returns: dict[str, Any] ### requests.models.Response.__setstate__ — def __setstate__(state: dict[str, Any]) -> None Parameters: state (dict[str, Any]) Returns: None ### requests.models.Response.__repr__ — def __repr__() -> str Returns: str ### requests.models.Response.__bool__ — def __bool__() -> bool Returns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. Returns: bool ### requests.models.Response.__nonzero__ — def __nonzero__() -> bool Returns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. Returns: bool ### requests.models.Response.__iter__ — def __iter__() -> Iterator[bytes] Allows you to use a response as an iterator. Returns: Iterator[bytes] ### requests.models.Response.iter_content — def iter_content(chunk_size: int | None = 1, decode_unicode: Literal[False] = False) -> Iterator[bytes] Parameters: chunk_size (int | None) = 1 decode_unicode (Literal[False]) = False Returns: Iterator[bytes] ### requests.models.Response.iter_content — def iter_content(chunk_size: int | None = 1, decode_unicode: Literal[True]) -> Iterator[str | bytes] Parameters: chunk_size (int | None) = 1 decode_unicode (Literal[True]) Returns: Iterator[str | bytes] ### requests.models.Response.iter_content — def iter_content(chunk_size: int | None = 1, decode_unicode: bool = False) -> Iterator[str | bytes] Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using encoding information from the response. If no encoding information is available, bytes will be returned. This can be bypassed by manually setting `encoding` on the response. Parameters: chunk_size (int | None) = 1 decode_unicode (bool) = False Returns: Iterator[str | bytes] ### requests.models.Response.iter_lines — def iter_lines(chunk_size: int = ITER_CHUNK_SIZE, decode_unicode: Literal[False] = False, delimiter: bytes | None = None) -> Iterator[bytes] Parameters: chunk_size (int) = ITER_CHUNK_SIZE decode_unicode (Literal[False]) = False delimiter (bytes | None) = None Returns: Iterator[bytes] ### requests.models.Response.iter_lines — def iter_lines(chunk_size: int = ITER_CHUNK_SIZE, decode_unicode: Literal[True], delimiter: str | bytes | None = None) -> Iterator[str | bytes] Parameters: chunk_size (int) = ITER_CHUNK_SIZE decode_unicode (Literal[True]) delimiter (str | bytes | None) = None Returns: Iterator[str | bytes] ### requests.models.Response.iter_lines — def iter_lines(chunk_size: int = ITER_CHUNK_SIZE, decode_unicode: bool = False, delimiter: str | bytes | None = None) -> Iterator[str | bytes] Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The decode_unicode param works the same as in `iter_content`, with the same caveats. .. note:: This method is not reentrant safe. Parameters: chunk_size (int) = ITER_CHUNK_SIZE decode_unicode (bool) = False delimiter (str | bytes | None) = None Returns: Iterator[str | bytes] ### requests.models.Response.json — def json(kwargs: Any) -> Any Decodes the JSON response body (if any) as a Python object. This may return a dictionary, list, etc. depending on what is in the response. Parameters: kwargs (Any) Returns: Any Raises: requests.exceptions.JSONDecodeError: If the response body does not contain valid json. ### requests.models.Response.raise_for_status — def raise_for_status() -> None Raises :class:`HTTPError`, if one occurred. Returns: None ### requests.models.Response.close — def close() -> None Releases the connection back to the pool. Once this method has been called the underlying ``raw`` object must not be accessed again. *Note: Should not normally need to be called explicitly.* Returns: None ## requests.sessions (module) ### requests.sessions.merge_setting — def merge_setting(request_setting: Any, session_setting: Any, dict_class: type = OrderedDict) -> Any Determines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` Parameters: request_setting (Any) session_setting (Any) dict_class (type) = OrderedDict Returns: Any ### requests.sessions.merge_hooks — def merge_hooks(request_hooks: _t.HooksType, session_hooks: _t.HooksType, dict_class: type = OrderedDict) -> _t.HooksType Properly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. Parameters: request_hooks (_t.HooksType) session_hooks (_t.HooksType) dict_class (type) = OrderedDict Returns: _t.HooksType ### requests.sessions.session — def session() -> Session Returns a :class:`Session` for context-management. .. deprecated:: 1.0.0 This method has been deprecated since version 1.0.0 and is only kept for backwards compatibility. New code should use :class:`~requests.sessions.Session` to create a session. This may be removed at a future date. Returns: Session ### requests.sessions.SessionRedirectMixin — class SessionRedirectMixin ### requests.sessions.SessionRedirectMixin.send — def send(request: PreparedRequest, kwargs: Any) -> Response Parameters: request (PreparedRequest) kwargs (Any) Returns: Response ### requests.sessions.SessionRedirectMixin.get_redirect_target — def get_redirect_target(resp: Response) -> str | None Receives a Response. Returns a redirect URI or ``None`` Parameters: resp (Response) Returns: str | None ### requests.sessions.SessionRedirectMixin.should_strip_auth — def should_strip_auth(old_url: str, new_url: str) -> bool Decide whether Authorization header should be removed when redirecting Parameters: old_url (str) new_url (str) Returns: bool ### requests.sessions.SessionRedirectMixin.resolve_redirects — def resolve_redirects(resp: Response, req: PreparedRequest, stream: bool = False, timeout: _t.TimeoutType = None, verify: _t.VerifyType = True, cert: _t.CertType = None, proxies: dict[str, str] | None = None, yield_requests: bool = False, adapter_kwargs: Any) -> Generator[Response, None, None] Receives a Response. Returns a generator of Responses or Requests. Parameters: resp (Response) req (PreparedRequest) stream (bool) = False timeout (_t.TimeoutType) = None verify (_t.VerifyType) = True cert (_t.CertType) = None proxies (dict[str, str] | None) = None yield_requests (bool) = False adapter_kwargs (Any) Returns: Generator[Response, None, None] ### requests.sessions.SessionRedirectMixin.rebuild_auth — def rebuild_auth(prepared_request: PreparedRequest, response: Response) -> None When being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. Parameters: prepared_request (PreparedRequest) response (Response) Returns: None ### requests.sessions.SessionRedirectMixin.rebuild_proxies — def rebuild_proxies(prepared_request: PreparedRequest, proxies: dict[str, str] | None) -> dict[str, str] This method re-evaluates the proxy configuration by considering the environment variables. If we are redirected to a URL covered by NO_PROXY, we strip the proxy configuration. Otherwise, we set missing proxy keys for this URL (in case they were stripped by a previous redirect). This method also replaces the Proxy-Authorization header where necessary. Parameters: prepared_request (PreparedRequest) proxies (dict[str, str] | None) Returns: dict[str, str] ### requests.sessions.SessionRedirectMixin.rebuild_method — def rebuild_method(prepared_request: PreparedRequest, response: Response) -> None When being redirected we may want to change the method of the request based on certain specs or browser behavior. Parameters: prepared_request (PreparedRequest) response (Response) Returns: None ### requests.sessions.Session — class Session(SessionRedirectMixin) A Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('https://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: ... s.get('https://httpbin.org/get') ### requests.sessions.Session.__enter__ — def __enter__() -> Self Returns: Self ### requests.sessions.Session.__exit__ — def __exit__(args: Any) -> None Parameters: args (Any) Returns: None ### requests.sessions.Session.prepare_request — def prepare_request(request: Request) -> PreparedRequest Constructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the Parameters: request (Request): :class:`Request` instance to prepare with this session's settings. Returns: PreparedRequest ### requests.sessions.Session.request — def request(method: str, url: _t.UriType, params: _t.ParamsType = None, data: _t.DataType = None, headers: _t.HeadersType = None, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None, files: _t.FilesType = None, auth: _t.AuthType = None, timeout: _t.TimeoutType = None, allow_redirects: bool = True, proxies: dict[str, str] | None = None, hooks: _t.HooksInputType | None = None, stream: bool | None = None, verify: _t.VerifyType | None = None, cert: _t.CertType = None, json: _t.JsonType = None) -> Response Constructs a :class:`Request `, prepares it and sends it. Returns :class:`Response ` object. Parameters: method (str): method for the new :class:`Request` object. url (_t.UriType): URL for the new :class:`Request` object. params (_t.ParamsType) = None: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. headers (_t.HeadersType) = None: (optional) Dictionary of HTTP Headers to send with the cookies (RequestsCookieJar | CookieJar | dict[str, str] | None) = None: (optional) Dict or CookieJar object to send with the files (_t.FilesType) = None: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. auth (_t.AuthType) = None: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. timeout (_t.TimeoutType) = None: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. allow_redirects (bool) = True: (optional) Set to True by default. proxies (dict[str, str] | None) = None: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. hooks (_t.HooksInputType | None) = None: (optional) Dictionary mapping hook name to one event or list of events, event must be callable. stream (bool | None) = None: (optional) whether to immediately download the response content. Defaults to ``False``. verify (_t.VerifyType | None) = None: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. When set to ``False``, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to ``False`` may be useful during local development or testing. cert (_t.CertType) = None: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. json (_t.JsonType) = None: (optional) json to send in the body of the Returns: Response ### requests.sessions.Session.get — def get(url: _t.UriType, params: _t.ParamsType = None, kwargs: Unpack[_t.GetKwargs]) -> Response Sends a GET request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. params (_t.ParamsType) = None: (optional) Dictionary, list of tuples or bytes to send in the query string for the :class:`Request`. kwargs (Unpack[_t.GetKwargs]) Returns: Response ### requests.sessions.Session.options — def options(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends a OPTIONS request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response ### requests.sessions.Session.head — def head(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends a HEAD request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response ### requests.sessions.Session.post — def post(url: _t.UriType, data: _t.DataType = None, json: _t.JsonType = None, kwargs: Unpack[_t.PostKwargs]) -> Response Sends a POST request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. json (_t.JsonType) = None: (optional) json to send in the body of the :class:`Request`. kwargs (Unpack[_t.PostKwargs]) Returns: Response ### requests.sessions.Session.put — def put(url: _t.UriType, data: _t.DataType = None, kwargs: Unpack[_t.DataKwargs]) -> Response Sends a PUT request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. kwargs (Unpack[_t.DataKwargs]) Returns: Response ### requests.sessions.Session.patch — def patch(url: _t.UriType, data: _t.DataType = None, kwargs: Unpack[_t.DataKwargs]) -> Response Sends a PATCH request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. data (_t.DataType) = None: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. kwargs (Unpack[_t.DataKwargs]) Returns: Response ### requests.sessions.Session.delete — def delete(url: _t.UriType, kwargs: Unpack[_t.RequestKwargs]) -> Response Sends a DELETE request. Returns :class:`Response` object. Parameters: url (_t.UriType): URL for the new :class:`Request` object. kwargs (Unpack[_t.RequestKwargs]) Returns: Response ### requests.sessions.Session.send — def send(request: PreparedRequest, kwargs: Any) -> Response Send a given PreparedRequest. Parameters: request (PreparedRequest) kwargs (Any) Returns: Response ### requests.sessions.Session.merge_environment_settings — def merge_environment_settings(url: str, proxies: dict[str, str] | None, stream: bool | None, verify: _t.VerifyType | None, cert: _t.CertType) -> dict[str, Any] Check the environment and merge it with some settings. Parameters: url (str) proxies (dict[str, str] | None) stream (bool | None) verify (_t.VerifyType | None) cert (_t.CertType) Returns: dict[str, Any] ### requests.sessions.Session.get_adapter — def get_adapter(url: str) -> BaseAdapter Returns the appropriate connection adapter for the given URL. Parameters: url (str) Returns: BaseAdapter ### requests.sessions.Session.close — def close() -> None Closes all adapters and as such the session Returns: None ### requests.sessions.Session.mount — def mount(prefix: str, adapter: BaseAdapter) -> None Registers a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. Parameters: prefix (str) adapter (BaseAdapter) Returns: None ### requests.sessions.Session.__getstate__ — def __getstate__() -> dict[str, Any] Returns: dict[str, Any] ### requests.sessions.Session.__setstate__ — def __setstate__(state: dict[str, Any]) -> None Parameters: state (dict[str, Any]) Returns: None ## requests.structures (module) ### requests.structures.CaseInsensitiveDict — class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]) A case-insensitive ``dict``-like object. Implements all methods and operations of ``MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['aCCEPT'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined. ### requests.structures.CaseInsensitiveDict.__setitem__ — def __setitem__(key: str, value: _VT) -> None Parameters: key (str) value (_VT) Returns: None ### requests.structures.CaseInsensitiveDict.__getitem__ — def __getitem__(key: str) -> _VT Parameters: key (str) Returns: _VT ### requests.structures.CaseInsensitiveDict.__delitem__ — def __delitem__(key: str) -> None Parameters: key (str) Returns: None ### requests.structures.CaseInsensitiveDict.__iter__ — def __iter__() -> Iterator[str] Returns: Iterator[str] ### requests.structures.CaseInsensitiveDict.__len__ — def __len__() -> int Returns: int ### requests.structures.CaseInsensitiveDict.lower_items — def lower_items() -> Iterator[tuple[str, _VT]] Like iteritems(), but with all lowercase keys. Returns: Iterator[tuple[str, _VT]] ### requests.structures.CaseInsensitiveDict.__eq__ — def __eq__(other: object) -> bool Parameters: other (object) Returns: bool ### requests.structures.CaseInsensitiveDict.copy — def copy() -> CaseInsensitiveDict[_VT] Returns: CaseInsensitiveDict[_VT] ### requests.structures.CaseInsensitiveDict.__repr__ — def __repr__() -> str Returns: str ### requests.structures.LookupDict — class LookupDict(dict[str, _VT]) Dictionary lookup object. ### requests.structures.LookupDict.__repr__ — def __repr__() -> str Returns: str ### requests.structures.LookupDict.__getattr__ — def __getattr__(key: str) -> _VT | None Parameters: key (str) Returns: _VT | None ### requests.structures.LookupDict.__getitem__ — def __getitem__(key: str) -> _VT | None Parameters: key (str) Returns: _VT | None ### requests.structures.LookupDict.get — def get(key: str, default: None = None) -> _VT | None Parameters: key (str) default (None) = None Returns: _VT | None ### requests.structures.LookupDict.get — def get(key: str, default: _D | _VT) -> _D | _VT Parameters: key (str) default (_D | _VT) Returns: _D | _VT ### requests.structures.LookupDict.get — def get(key: str, default: _D | None = None) -> _VT | _D | None Parameters: key (str) default (_D | None) = None Returns: _VT | _D | None ## requests.utils (module) ### requests.utils.proxy_bypass_registry — def proxy_bypass_registry(host: str) -> bool Parameters: host (str) Returns: bool ### requests.utils.proxy_bypass — def proxy_bypass(host: str) -> bool Return True, if the host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. Parameters: host (str) Returns: bool ### requests.utils.dict_to_sequence — def dict_to_sequence(d: _t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]) -> Iterable[tuple[Any, Any]] Returns an internal sequence dictionary update. Parameters: d (_t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]) Returns: Iterable[tuple[Any, Any]] ### requests.utils.super_len — def super_len(o: Any) -> int Parameters: o (Any) Returns: int ### requests.utils.get_netrc_auth — def get_netrc_auth(url: _t.UriType, raise_errors: bool = False) -> tuple[str, str] | None Returns the Requests tuple auth for a given url from netrc. Parameters: url (_t.UriType) raise_errors (bool) = False Returns: tuple[str, str] | None ### requests.utils.guess_filename — def guess_filename(obj: Any) -> str | None Tries to guess the filename of the given object. Parameters: obj (Any) Returns: str | None ### requests.utils.extract_zipped_paths — def extract_zipped_paths(path: str) -> str Replace nonexistent paths that look like they refer to a member of a zip archive with the location of an extracted copy of the target, or else just return the provided path unchanged. Parameters: path (str) Returns: str ### requests.utils.atomic_open — def atomic_open(filename: str) -> Generator[BufferedWriter, None, None] Write a file to the disk in an atomic fashion Parameters: filename (str) Returns: Generator[BufferedWriter, None, None] ### requests.utils.from_key_val_list — def from_key_val_list(value: Mapping[Any, Any] | Iterable[tuple[Any, Any]] | None) -> dict[Any, Any] | None Take an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g., Parameters: value (Mapping[Any, Any] | Iterable[tuple[Any, Any]] | None) Returns: dict[Any, Any] | None ### requests.utils.to_key_val_list — def to_key_val_list(value: None) -> None Parameters: value (None) Returns: None ### requests.utils.to_key_val_list — def to_key_val_list(value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]]) -> list[tuple[_KT, _VT]] Parameters: value (_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]]) Returns: list[tuple[_KT, _VT]] ### requests.utils.to_key_val_list — def to_key_val_list(value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None) -> list[tuple[_KT, _VT]] | None Take an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g., Parameters: value (_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None) Returns: list[tuple[_KT, _VT]] | None ### requests.utils.parse_list_header — def parse_list_header(value: str) -> list[str] Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing. It basically works like :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the Parameters: value (str): a string with a list header. Returns: list[str] — :class:`list` ### requests.utils.parse_dict_header — def parse_dict_header(value: str) -> dict[str, str | None] Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict: >>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] If there is no value for a key it will be `None`: >>> parse_dict_header('key_without_value') {'key_without_value': None} To create a header from the :class:`dict` again, use the Parameters: value (str): a string with a dict header. Returns: dict[str, str | None] — :class:`dict` ### requests.utils.unquote_header_value — def unquote_header_value(value: str, is_filename: bool = False) -> str Unquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. Parameters: value (str): the header value to unquote. is_filename (bool) = False Returns: str ### requests.utils.dict_from_cookiejar — def dict_from_cookiejar(cj: CookieJar) -> dict[str, str | None] Returns a key/value dictionary from a CookieJar. Parameters: cj (CookieJar): CookieJar object to extract cookies from. Returns: dict[str, str | None] ### requests.utils.add_dict_to_cookiejar — def add_dict_to_cookiejar(cj: CookieJar, cookie_dict: dict[str, str]) -> CookieJar Returns a CookieJar from a key/value dictionary. Parameters: cj (CookieJar): CookieJar to insert cookies into. cookie_dict (dict[str, str]): Dict of key/values to insert into CookieJar. Returns: CookieJar ### requests.utils.get_encodings_from_content — def get_encodings_from_content(content: str) -> list[str] Returns encodings from given content string. Parameters: content (str): bytestring to extract encodings from. Returns: list[str] ### requests.utils.get_encoding_from_headers — def get_encoding_from_headers(headers: CaseInsensitiveDict[str]) -> str | None Returns encodings from given HTTP Header Dict. Parameters: headers (CaseInsensitiveDict[str]): dictionary to extract encoding from. Returns: str | None ### requests.utils.stream_decode_response_unicode — def stream_decode_response_unicode(iterator: Iterable[bytes], r: Response) -> Generator[str | bytes, None, None] Stream decodes an iterator. Parameters: iterator (Iterable[bytes]) r (Response) Returns: Generator[str | bytes, None, None] ### requests.utils.iter_slices — def iter_slices(string: bytes, slice_length: int | None) -> Generator[bytes, None, None] Parameters: string (bytes) slice_length (int | None) Returns: Generator[bytes, None, None] ### requests.utils.iter_slices — def iter_slices(string: str, slice_length: int | None) -> Generator[str, None, None] Parameters: string (str) slice_length (int | None) Returns: Generator[str, None, None] ### requests.utils.iter_slices — def iter_slices(string: bytes | str, slice_length: int | None) -> Generator[bytes | str, None, None] Iterate over slices of a string. Parameters: string (bytes | str) slice_length (int | None) Returns: Generator[bytes | str, None, None] ### requests.utils.get_unicode_from_response — def get_unicode_from_response(r: Response) -> str | bytes | None Returns the requested content back in unicode. Parameters: r (Response): Response object to get unicode content from. Returns: str | bytes | None ### requests.utils.unquote_unreserved — def unquote_unreserved(uri: str) -> str Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. Parameters: uri (str) Returns: str ### requests.utils.requote_uri — def requote_uri(uri: str) -> str Re-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. Parameters: uri (str) Returns: str ### requests.utils.address_in_network — def address_in_network(ip: str, net: str) -> bool This function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 Parameters: ip (str) net (str) Returns: bool ### requests.utils.dotted_netmask — def dotted_netmask(mask: int) -> str Converts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 Parameters: mask (int) Returns: str ### requests.utils.is_ipv4_address — def is_ipv4_address(string_ip: str) -> bool Parameters: string_ip (str) Returns: bool ### requests.utils.is_valid_cidr — def is_valid_cidr(string_network: str) -> bool Very simple check of the cidr format in no_proxy variable. Parameters: string_network (str) Returns: bool ### requests.utils.set_environ — def set_environ(env_name: str, value: str | None) -> Generator[None, None, None] Set the environment variable 'env_name' to 'value' Save previous value, yield, and then restore the previous value stored in the environment variable 'env_name'. If 'value' is None, do nothing Parameters: env_name (str) value (str | None) Returns: Generator[None, None, None] ### requests.utils.should_bypass_proxies — def should_bypass_proxies(url: str, no_proxy: str | None) -> bool Returns whether we should bypass proxies or not. Parameters: url (str) no_proxy (str | None) Returns: bool ### requests.utils.get_environ_proxies — def get_environ_proxies(url: str, no_proxy: str | None = None) -> dict[str, str] Return a dict of environment proxies. Parameters: url (str) no_proxy (str | None) = None Returns: dict[str, str] ### requests.utils.select_proxy — def select_proxy(url: str, proxies: dict[str, str] | None) -> str | None Select a proxy for the url, if applicable. Parameters: url (str): The url being for the request proxies (dict[str, str] | None): A dictionary of schemes or schemes and hosts to proxy URLs Returns: str | None ### requests.utils.resolve_proxies — def resolve_proxies(request: Request | PreparedRequest, proxies: dict[str, str] | None, trust_env: bool = True) -> dict[str, str] This method takes proxy information from a request and configuration input to resolve a mapping of target proxies. This will consider settings such as NO_PROXY to strip proxy configurations. Parameters: request (Request | PreparedRequest): Request or PreparedRequest proxies (dict[str, str] | None): A dictionary of schemes or schemes and hosts to proxy URLs trust_env (bool) = True: Boolean declaring whether to trust environment configs Returns: dict[str, str] ### requests.utils.default_user_agent — def default_user_agent(name: str = "python-requests") -> str Return a string representing the default user agent. Parameters: name (str) = "python-requests" Returns: str ### requests.utils.default_headers — def default_headers() -> CaseInsensitiveDict[str] Returns: CaseInsensitiveDict[str] ### requests.utils.parse_header_links — def parse_header_links(value: str) -> list[dict[str, str]] Return a list of parsed link headers proxies. i.e. Link: ; rel=front; type="image/jpeg",; rel=back;type="image/jpeg" Parameters: value (str) Returns: list[dict[str, str]] ### requests.utils.guess_json_utf — def guess_json_utf(data: bytes) -> str | None Parameters: data (bytes) Returns: str | None ### requests.utils.prepend_scheme_if_needed — def prepend_scheme_if_needed(url: str, new_scheme: str) -> str Given a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument. Parameters: url (str) new_scheme (str) Returns: str ### requests.utils.get_auth_from_url — def get_auth_from_url(url: str) -> tuple[str, str] Given a url with authentication components, extract them into a tuple of username,password. Parameters: url (str) Returns: tuple[str, str] ### requests.utils.check_header_validity — def check_header_validity(header: tuple[str | bytes, str | bytes]) -> None Verifies that header parts don't contain leading whitespace reserved characters, or return characters. Parameters: header (tuple[str | bytes, str | bytes]): tuple, in the format (name, value). Returns: None ### requests.utils.urldefragauth — def urldefragauth(url: str) -> str Given a url remove the fragment and the authentication part. Parameters: url (str) Returns: str ### requests.utils.rewind_body — def rewind_body(prepared_request: PreparedRequest) -> None Move file pointer back to its recorded starting position so it can be read again on redirect. Parameters: prepared_request (PreparedRequest) Returns: None ## requests.cookies (module) ### requests.cookies.extract_cookies_to_jar — def extract_cookies_to_jar(jar: CookieJar, request: PreparedRequest, response: Any) -> None Extract the cookies from the response into a CookieJar. Parameters: jar (CookieJar): http.cookiejar.CookieJar (not necessarily a RequestsCookieJar) request (PreparedRequest): our own requests.Request object response (Any): urllib3.HTTPResponse object Returns: None ### requests.cookies.get_cookie_header — def get_cookie_header(jar: CookieJar, request: PreparedRequest) -> str | None Produce an appropriate Cookie header string to be sent with `request`, or None. Parameters: jar (CookieJar) request (PreparedRequest) Returns: str | None ### requests.cookies.remove_cookie_by_name — def remove_cookie_by_name(cookiejar: CookieJar, name: str, domain: str | None = None, path: str | None = None) -> None Unsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). Parameters: cookiejar (CookieJar) name (str) domain (str | None) = None path (str | None) = None Returns: None ### requests.cookies.update — def update(self, other: CookieJar | SupportsKeysAndGetItem[str, str]) -> None Updates this jar with cookies from another CookieJar or dict-like Parameters: self other (CookieJar | SupportsKeysAndGetItem[str, str]) Returns: None ### requests.cookies.copy — def copy(self) -> RequestsCookieJar Return a copy of this RequestsCookieJar. Parameters: self Returns: RequestsCookieJar ### requests.cookies.get_policy — def get_policy(self) -> CookiePolicy Return the CookiePolicy instance used. Parameters: self Returns: CookiePolicy ### requests.cookies.create_cookie — def create_cookie(name: str, value: str, kwargs: Any) -> Cookie Make a cookie from underspecified parameters. By default, the pair of `name` and `value` will be set for the domain '' and sent on every request (this is sometimes called a "supercookie"). Parameters: name (str) value (str) kwargs (Any) Returns: Cookie ### requests.cookies.morsel_to_cookie — def morsel_to_cookie(morsel: Morsel[Any]) -> Cookie Convert a Morsel object into a Cookie containing the one k/v pair. Parameters: morsel (Morsel[Any]) Returns: Cookie ### requests.cookies.cookiejar_from_dict — def cookiejar_from_dict(cookie_dict: dict[str, str] | None, cookiejar: None = None, overwrite: bool = True) -> RequestsCookieJar Parameters: cookie_dict (dict[str, str] | None) cookiejar (None) = None overwrite (bool) = True Returns: RequestsCookieJar ### requests.cookies.cookiejar_from_dict — def cookiejar_from_dict(cookie_dict: dict[str, str] | None, cookiejar: _CookieJarT, overwrite: bool = True) -> _CookieJarT Parameters: cookie_dict (dict[str, str] | None) cookiejar (_CookieJarT) overwrite (bool) = True Returns: _CookieJarT ### requests.cookies.cookiejar_from_dict — def cookiejar_from_dict(cookie_dict: dict[str, str] | None, cookiejar: CookieJar | None = None, overwrite: bool = True) -> CookieJar Returns a CookieJar from a key/value dictionary. Parameters: cookie_dict (dict[str, str] | None): Dict of key/values to insert into CookieJar. cookiejar (CookieJar | None) = None: (optional) A cookiejar to add the cookies to. overwrite (bool) = True: (optional) If False, will not replace cookies already in the jar with new ones. Returns: CookieJar ### requests.cookies.merge_cookies — def merge_cookies(cookiejar: CookieJar, cookies: dict[str, str] | CookieJar | None) -> CookieJar Add cookies to cookiejar and returns a merged CookieJar. Parameters: cookiejar (CookieJar): CookieJar object to add the cookies to. cookies (dict[str, str] | CookieJar | None): Dictionary or CookieJar object to be added. Returns: CookieJar ### requests.cookies.MockRequest — class MockRequest Wraps a `requests.PreparedRequest` to mimic a `urllib2.Request`. The code in `http.cookiejar.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. ### requests.cookies.MockRequest.get_type — def get_type() -> str Returns: str ### requests.cookies.MockRequest.get_host — def get_host() -> str Returns: str ### requests.cookies.MockRequest.get_origin_req_host — def get_origin_req_host() -> str Returns: str ### requests.cookies.MockRequest.get_full_url — def get_full_url() -> str Returns: str ### requests.cookies.MockRequest.is_unverifiable — def is_unverifiable() -> bool Returns: bool ### requests.cookies.MockRequest.has_header — def has_header(name: str) -> bool Parameters: name (str) Returns: bool ### requests.cookies.MockRequest.get_header — def get_header(name: str, default: str | None = None) -> str | None Parameters: name (str) default (str | None) = None Returns: str | None ### requests.cookies.MockRequest.add_header — def add_header(key: str, val: str) -> None cookiejar has no legitimate use for this method; add it back if you find one. Parameters: key (str) val (str) Returns: None ### requests.cookies.MockRequest.add_unredirected_header — def add_unredirected_header(name: str, value: str) -> None Parameters: name (str) value (str) Returns: None ### requests.cookies.MockRequest.get_new_headers — def get_new_headers() -> dict[str, str] Returns: dict[str, str] ### requests.cookies.MockResponse — class MockResponse Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`. ...what? Basically, expose the parsed HTTP headers from the server response the way `http.cookiejar` expects to see them. ### requests.cookies.MockResponse.info — def info() -> Any Returns: Any ### requests.cookies.MockResponse.getheaders — def getheaders(name: str) -> Any Parameters: name (str) Returns: Any ### requests.cookies.RequestsCookieJar — class RequestsCookieJar(CookieJar, MutableMapping[str, str | None]) Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n). ### requests.cookies.RequestsCookieJar.get — def get(name: str, default: str | None = None, domain: str | None = None, path: str | None = None) -> str | None Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. .. warning:: operation is O(n), not O(1). Parameters: name (str) default (str | None) = None domain (str | None) = None path (str | None) = None Returns: str | None ### requests.cookies.RequestsCookieJar.set — def set(name: str, value: str | Morsel[dict[str, str]] | None, kwargs: Any) -> Cookie | None Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Parameters: name (str) value (str | Morsel[dict[str, str]] | None) kwargs (Any) Returns: Cookie | None ### requests.cookies.RequestsCookieJar.iterkeys — def iterkeys() -> Iterator[str] Dict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). Returns: Iterator[str] ### requests.cookies.RequestsCookieJar.keys — def keys() -> list[str] Dict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). Returns: list[str] ### requests.cookies.RequestsCookieJar.itervalues — def itervalues() -> Iterator[str | None] Dict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). Returns: Iterator[str | None] ### requests.cookies.RequestsCookieJar.values — def values() -> list[str | None] Dict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). Returns: list[str | None] ### requests.cookies.RequestsCookieJar.iteritems — def iteritems() -> Iterator[tuple[str, str | None]] Dict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). Returns: Iterator[tuple[str, str | None]] ### requests.cookies.RequestsCookieJar.items — def items() -> list[tuple[str, str | None]] Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs. .. seealso:: keys() and values(). Returns: list[tuple[str, str | None]] ### requests.cookies.RequestsCookieJar.list_domains — def list_domains() -> list[str] Utility method to list all the domains in the jar. Returns: list[str] ### requests.cookies.RequestsCookieJar.list_paths — def list_paths() -> list[str] Utility method to list all the paths in the jar. Returns: list[str] ### requests.cookies.RequestsCookieJar.multiple_domains — def multiple_domains() -> bool Returns True if there are multiple domains in the jar. Returns False otherwise. Returns: bool ### requests.cookies.RequestsCookieJar.get_dict — def get_dict(domain: str | None = None, path: str | None = None) -> dict[str, str | None] Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements. Parameters: domain (str | None) = None path (str | None) = None Returns: dict[str, str | None] ### requests.cookies.RequestsCookieJar.__iter__ — def __iter__() -> Iterator[Cookie] RequestCookieJar's __iter__ comes from CookieJar not MutableMapping. Returns: Iterator[Cookie] ### requests.cookies.RequestsCookieJar.__contains__ — def __contains__(name: object) -> bool Parameters: name (object) Returns: bool ### requests.cookies.RequestsCookieJar.__getitem__ — def __getitem__(name: str) -> str | None Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1). Parameters: name (str) Returns: str | None ### requests.cookies.RequestsCookieJar.__setitem__ — def __setitem__(name: str, value: str | Morsel[dict[str, str]] | None) -> None Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead. Parameters: name (str) value (str | Morsel[dict[str, str]] | None) Returns: None ### requests.cookies.RequestsCookieJar.__delitem__ — def __delitem__(name: str) -> None Deletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s ``remove_cookie_by_name()``. Parameters: name (str) Returns: None ### requests.cookies.RequestsCookieJar.set_cookie — def set_cookie(cookie: Cookie, args: Any, kwargs: Any) -> None Parameters: cookie (Cookie) args (Any) kwargs (Any) Returns: None ### requests.cookies.CookieConflictError — class CookieConflictError(RuntimeError) There are two cookies that meet the criteria specified in the cookie jar. Use .get and .set and include domain and path args in order to be more specific. ## requests.adapters (module) ### requests.adapters.SOCKSProxyManager — def SOCKSProxyManager(args: Any, kwargs: Any) -> None Parameters: args (Any) kwargs (Any) Returns: None ### requests.adapters.BaseAdapter — class BaseAdapter The Base Transport Adapter ### requests.adapters.BaseAdapter.send — def send(request: PreparedRequest, stream: bool = False, timeout: _t.TimeoutType = None, verify: _t.VerifyType = True, cert: _t.CertType = None, proxies: dict[str, str] | None = None) -> Response Sends PreparedRequest object. Returns Response object. Parameters: request (PreparedRequest): The :class:`PreparedRequest ` being sent. stream (bool) = False: (optional) Whether to stream the request content. timeout (_t.TimeoutType) = None: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. verify (_t.VerifyType) = True: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use cert (_t.CertType) = None: (optional) Any user-provided SSL certificate to be trusted. proxies (dict[str, str] | None) = None: (optional) The proxies dictionary to apply to the request. Returns: Response ### requests.adapters.BaseAdapter.close — def close() -> None Cleans up adapter specific items. Returns: None ### requests.adapters.HTTPAdapter — class HTTPAdapter(BaseAdapter) The built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session ` class under the covers. ### requests.adapters.HTTPAdapter.__getstate__ — def __getstate__() -> dict[str, Any] Returns: dict[str, Any] ### requests.adapters.HTTPAdapter.__setstate__ — def __setstate__(state: dict[str, Any]) -> None Parameters: state (dict[str, Any]) Returns: None ### requests.adapters.HTTPAdapter.init_poolmanager — def init_poolmanager(connections: int, maxsize: int, block: bool = DEFAULT_POOLBLOCK, pool_kwargs: Any) -> None Initializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the Parameters: connections (int): The number of urllib3 connection pools to cache. maxsize (int): The maximum number of connections to save in the pool. block (bool) = DEFAULT_POOLBLOCK: Block when no free connections are available. pool_kwargs (Any): Extra keyword arguments used to initialize the Pool Manager. Returns: None ### requests.adapters.HTTPAdapter.proxy_manager_for — def proxy_manager_for(proxy: str, proxy_kwargs: Any) -> Any Return urllib3 ProxyManager for the given proxy. This method should not be called from user code, and is only exposed for use when subclassing the Parameters: proxy (str): The proxy to return a urllib3 ProxyManager for. proxy_kwargs (Any): Extra keyword arguments used to configure the Proxy Manager. Returns: Any — ProxyManager ### requests.adapters.HTTPAdapter.cert_verify — def cert_verify(conn: Any, url: str, verify: _t.VerifyType, cert: _t.CertType) -> None Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the Parameters: conn (Any): The urllib3 connection object associated with the cert. url (str): The requested URL. verify (_t.VerifyType): Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use cert (_t.CertType): The SSL certificate to verify. Returns: None ### requests.adapters.HTTPAdapter.build_response — def build_response(req: PreparedRequest, resp: Any) -> Response Builds a :class:`Response ` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the Parameters: req (PreparedRequest): The :class:`PreparedRequest ` used to generate the response. resp (Any): The urllib3 response object. Returns: Response ### requests.adapters.HTTPAdapter.build_connection_pool_key_attributes — def build_connection_pool_key_attributes(request: PreparedRequest, verify: _t.VerifyType, cert: _t.CertType = None) -> tuple[dict[str, Any], dict[str, Any]] Build the PoolKey attributes used by urllib3 to return a connection. This looks at the PreparedRequest, the user-specified verify value, and the value of the cert parameter to determine what PoolKey values to use to select a connection from a given urllib3 Connection Pool. The SSL related pool key arguments are not consistently set. As of this writing, use the following to determine what keys may be in that dictionary: * If ``verify`` is ``True``, ``"ssl_context"`` will be set and will be the default Requests SSL Context * If ``verify`` is ``False``, ``"ssl_context"`` will not be set but ``"cert_reqs"`` will be set * If ``verify`` is a string, (i.e., it is a user-specified trust bundle) ``"ca_certs"`` will be set if the string is not a directory recognized by :py:func:`os.path.isdir`, otherwise ``"ca_cert_dir"`` will be set. * If ``"cert"`` is specified, ``"cert_file"`` will always be set. If ``"cert"`` is a tuple with a second item, ``"key_file"`` will also be present To override these settings, one may subclass this class, call this method and use the above logic to change parameters as desired. For example, if one wishes to use a custom :py:class:`ssl.SSLContext` one must both set ``"ssl_context"`` and based on what else they require, alter the other keys to ensure the desired behaviour. Parameters: request (PreparedRequest): The PreparedRequest being sent over the connection. verify (_t.VerifyType): Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. cert (_t.CertType) = None: (optional) Any user-provided SSL certificate for client authentication (a.k.a., mTLS). This may be a string (i.e., just the path to a file which holds both certificate and key) or a tuple of length 2 with the certificate file path and key file path. Returns: tuple[dict[str, Any], dict[str, Any]] — A tuple of two dictionaries. The first is the "host parameters" portion of the Pool Key including scheme, hostname, and port. The second is a dictionary of SSLContext related parameters. ### requests.adapters.HTTPAdapter.get_connection_with_tls_context — def get_connection_with_tls_context(request: PreparedRequest, verify: _t.VerifyType, proxies: dict[str, str] | None = None, cert: _t.CertType = None) -> HTTPConnectionPool Returns a urllib3 connection for the given request and TLS settings. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. Parameters: request (PreparedRequest): The :class:`PreparedRequest ` object to be sent over the connection. verify (_t.VerifyType): Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. proxies (dict[str, str] | None) = None: (optional) The proxies dictionary to apply to the request. cert (_t.CertType) = None: (optional) Any user-provided SSL certificate to be used for client authentication (a.k.a., mTLS). Returns: HTTPConnectionPool ### requests.adapters.HTTPAdapter.get_connection — def get_connection(url: str, proxies: dict[str, str] | None = None) -> HTTPConnectionPool DEPRECATED: Users should move to `get_connection_with_tls_context` for all subclasses of HTTPAdapter using Requests>=2.32.2. Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the Parameters: url (str): The URL to connect to. proxies (dict[str, str] | None) = None: (optional) A Requests-style dictionary of proxies used on this request. Returns: HTTPConnectionPool ### requests.adapters.HTTPAdapter.close — def close() -> None Disposes of any internal state. Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections. Returns: None ### requests.adapters.HTTPAdapter.request_url — def request_url(request: PreparedRequest, proxies: dict[str, str] | None) -> str Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the Parameters: request (PreparedRequest): The :class:`PreparedRequest ` being sent. proxies (dict[str, str] | None): A dictionary of schemes or schemes and hosts to proxy URLs. Returns: str ### requests.adapters.HTTPAdapter.add_headers — def add_headers(request: PreparedRequest, kwargs: Any) -> None Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter `. This should not be called from user code, and is only exposed for use when subclassing the Parameters: request (PreparedRequest): The :class:`PreparedRequest ` to add headers to. kwargs (Any): The keyword arguments from the call to send(). Returns: None ### requests.adapters.HTTPAdapter.proxy_headers — def proxy_headers(proxy: str) -> dict[str, str] Returns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used. This should not be called from user code, and is only exposed for use when subclassing the Parameters: proxy (str): The url of the proxy being used for this request. Returns: dict[str, str] ### requests.adapters.HTTPAdapter.send — def send(request: PreparedRequest, stream: bool = False, timeout: _t.TimeoutType = None, verify: _t.VerifyType = True, cert: _t.CertType = None, proxies: dict[str, str] | None = None) -> Response Sends PreparedRequest object. Returns Response object. Parameters: request (PreparedRequest): The :class:`PreparedRequest ` being sent. stream (bool) = False: (optional) Whether to stream the request content. timeout (_t.TimeoutType) = None: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. verify (_t.VerifyType) = True: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use cert (_t.CertType) = None: (optional) Any user-provided SSL certificate to be trusted. proxies (dict[str, str] | None) = None: (optional) The proxies dictionary to apply to the request. Returns: Response ## requests.auth (module) ### requests.auth.AuthBase — class AuthBase Base class that all auth implementations derive from ### requests.auth.AuthBase.__call__ — def __call__(r: PreparedRequest) -> PreparedRequest Parameters: r (PreparedRequest) Returns: PreparedRequest ### requests.auth.HTTPBasicAuth — class HTTPBasicAuth(AuthBase) Attaches HTTP Basic Authentication to the given Request object. ### requests.auth.HTTPBasicAuth.__eq__ — def __eq__(other: object) -> bool Parameters: other (object) Returns: bool ### requests.auth.HTTPBasicAuth.__ne__ — def __ne__(other: Any) -> bool Parameters: other (Any) Returns: bool ### requests.auth.HTTPBasicAuth.__call__ — def __call__(r: PreparedRequest) -> PreparedRequest Parameters: r (PreparedRequest) Returns: PreparedRequest ### requests.auth.HTTPProxyAuth — class HTTPProxyAuth(HTTPBasicAuth) Attaches HTTP Proxy Authentication to a given Request object. ### requests.auth.HTTPProxyAuth.__call__ — def __call__(r: PreparedRequest) -> PreparedRequest Parameters: r (PreparedRequest) Returns: PreparedRequest ### requests.auth.HTTPDigestAuth — class HTTPDigestAuth(AuthBase) Attaches HTTP Digest Authentication to the given Request object. ### requests.auth.HTTPDigestAuth.init_per_thread_state — def init_per_thread_state() -> None Returns: None ### requests.auth.HTTPDigestAuth.build_digest_header — def build_digest_header(method: str, url: str) -> str | None Parameters: method (str) url (str) Returns: str | None ### requests.auth.HTTPDigestAuth.handle_redirect — def handle_redirect(r: Response, kwargs: Any) -> None Reset num_401_calls counter on redirects. Parameters: r (Response) kwargs (Any) Returns: None ### requests.auth.HTTPDigestAuth.handle_401 — def handle_401(r: Response, kwargs: Any) -> Response Takes the given response and tries digest-auth, if needed. Parameters: r (Response) kwargs (Any) Returns: Response