MCPcopy
hub / github.com/psf/requests / prepare_cookies

Method prepare_cookies

src/requests/models.py:697–718  ·  view source on GitHub ↗

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 t

(
        self, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None
    )

Source from the content-addressed store, hash-verified

695 self.prepare_content_length(self.body)
696
697 def prepare_cookies(
698 self, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None
699 ) -> None:
700 """Prepares the given HTTP cookie data.
701
702 This function eventually generates a ``Cookie`` header from the
703 given cookies using cookielib. Due to cookielib's design, the header
704 will not be regenerated if it already exists, meaning this function
705 can only be called once for the life of the
706 :class:`PreparedRequest <PreparedRequest>` object. Any subsequent calls
707 to ``prepare_cookies`` will have no actual effect, unless the "Cookie"
708 header is removed beforehand.
709 """
710 if isinstance(cookies, cookielib.CookieJar):
711 self._cookies = cookies
712 else:
713 self._cookies = cookiejar_from_dict(cookies)
714
715 cookies_jar = cast("CookieJar", self._cookies)
716 cookie_header = get_cookie_header(cookies_jar, self)
717 if cookie_header is not None:
718 self.headers["Cookie"] = cookie_header
719
720 def prepare_hooks(self, hooks: _t.HooksInputType | None) -> None:
721 """Prepares the given hooks."""

Callers 3

prepareMethod · 0.95
handle_401Method · 0.80
resolve_redirectsMethod · 0.80

Calls 2

cookiejar_from_dictFunction · 0.85
get_cookie_headerFunction · 0.85

Tested by

no test coverage detected