send() — requests Function Reference
Architecture documentation for the send() function in sessions.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 22824d7d_af0c_f593_6513_06ba28a4fc56["send()"] b4dad953_9227_8b3f_4041_3f8f1f9f0b29["Session"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|defined in| b4dad953_9227_8b3f_4041_3f8f1f9f0b29 cbf6862f_d124_817f_3342_f1142c276f25["resolve_redirects()"] cbf6862f_d124_817f_3342_f1142c276f25 -->|calls| 22824d7d_af0c_f593_6513_06ba28a4fc56 71102afa_b9d8_769c_e8b8_1db9a083fa11["request()"] 71102afa_b9d8_769c_e8b8_1db9a083fa11 -->|calls| 22824d7d_af0c_f593_6513_06ba28a4fc56 893b9da1_2923_c881_f9ef_c68d705ceea4["get_adapter()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 893b9da1_2923_c881_f9ef_c68d705ceea4 cbf6862f_d124_817f_3342_f1142c276f25["resolve_redirects()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| cbf6862f_d124_817f_3342_f1142c276f25 78f79a1e_c8bc_1d85_cefa_cf45d6efb42a["resolve_proxies()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 78f79a1e_c8bc_1d85_cefa_cf45d6efb42a e5f3beee_4f0d_bcf5_4af9_52d8658ab65f["get()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| e5f3beee_4f0d_bcf5_4af9_52d8658ab65f acde67db_dae5_e069_b8dd_39c38bbf6e2d["preferred_clock()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| acde67db_dae5_e069_b8dd_39c38bbf6e2d 71102afa_b9d8_769c_e8b8_1db9a083fa11["request()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 71102afa_b9d8_769c_e8b8_1db9a083fa11 924b0ea5_0624_ed50_4e16_6cf84750b162["dispatch_hook()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 924b0ea5_0624_ed50_4e16_6cf84750b162 55052edd_2a43_f298_b8d3_9fb1f2641e84["extract_cookies_to_jar()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 55052edd_2a43_f298_b8d3_9fb1f2641e84 d723c9c6_8627_9b28_a441_3b8f522e7521["next()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| d723c9c6_8627_9b28_a441_3b8f522e7521 66fc1563_b020_b369_a505_bc9abe7cf66d["send()"] 22824d7d_af0c_f593_6513_06ba28a4fc56 -->|calls| 66fc1563_b020_b369_a505_bc9abe7cf66d style 22824d7d_af0c_f593_6513_06ba28a4fc56 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/sessions.py lines 674–749
def send(self, request, **kwargs):
"""Send a given PreparedRequest.
:rtype: requests.Response
"""
# Set defaults that the hooks can utilize to ensure they always have
# the correct parameters to reproduce the previous request.
kwargs.setdefault("stream", self.stream)
kwargs.setdefault("verify", self.verify)
kwargs.setdefault("cert", self.cert)
if "proxies" not in kwargs:
kwargs["proxies"] = resolve_proxies(request, self.proxies, self.trust_env)
# It's possible that users might accidentally send a Request object.
# Guard against that specific failure case.
if isinstance(request, Request):
raise ValueError("You can only send PreparedRequests.")
# Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop("allow_redirects", True)
stream = kwargs.get("stream")
hooks = request.hooks
# Get the appropriate adapter to use
adapter = self.get_adapter(url=request.url)
# Start time (approximately) of the request
start = preferred_clock()
# Send the request
r = adapter.send(request, **kwargs)
# Total elapsed time of the request (approximately)
elapsed = preferred_clock() - start
r.elapsed = timedelta(seconds=elapsed)
# Response manipulation hooks
r = dispatch_hook("response", hooks, r, **kwargs)
# Persist cookies
if r.history:
# If the hooks create history then we want those cookies too
for resp in r.history:
extract_cookies_to_jar(self.cookies, resp.request, resp.raw)
extract_cookies_to_jar(self.cookies, request, r.raw)
# Resolve redirects if allowed.
if allow_redirects:
# Redirect resolving generator.
gen = self.resolve_redirects(r, request, **kwargs)
history = [resp for resp in gen]
else:
history = []
# Shuffle things around if there's history.
if history:
# Insert the first (original) request at the start
history.insert(0, r)
# Get the last request made
r = history.pop()
r.history = history
# If redirects aren't being followed, store the response on the Request for Response.next().
if not allow_redirects:
try:
r._next = next(
self.resolve_redirects(r, request, yield_requests=True, **kwargs)
)
except StopIteration:
pass
if not stream:
r.content
return r
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does send() do?
send() is a function in the requests codebase, defined in src/requests/sessions.py.
Where is send() defined?
send() is defined in src/requests/sessions.py at line 674.
What does send() call?
send() calls 10 function(s): dispatch_hook, extract_cookies_to_jar, get, get_adapter, next, preferred_clock, request, resolve_proxies, and 2 more.
What calls send()?
send() is called by 2 function(s): request, resolve_redirects.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free