Send a given PreparedRequest. :rtype: requests.Response
(self, request: PreparedRequest, **kwargs: Any)
| 750 | return self.request("DELETE", url, **kwargs) |
| 751 | |
| 752 | def send(self, request: PreparedRequest, **kwargs: Any) -> Response: |
| 753 | """Send a given PreparedRequest. |
| 754 | |
| 755 | :rtype: requests.Response |
| 756 | """ |
| 757 | # Set defaults that the hooks can utilize to ensure they always have |
| 758 | # the correct parameters to reproduce the previous request. |
| 759 | kwargs.setdefault("stream", self.stream) |
| 760 | kwargs.setdefault("verify", self.verify) |
| 761 | kwargs.setdefault("cert", self.cert) |
| 762 | if "proxies" not in kwargs: |
| 763 | kwargs["proxies"] = resolve_proxies(request, self.proxies, self.trust_env) |
| 764 | |
| 765 | # It's possible that users might accidentally send a Request object. |
| 766 | # Guard against that specific failure case. |
| 767 | if isinstance(request, Request): |
| 768 | raise ValueError("You can only send PreparedRequests.") |
| 769 | |
| 770 | assert _is_prepared(request) |
| 771 | |
| 772 | # Set up variables needed for resolve_redirects and dispatching of hooks |
| 773 | allow_redirects = kwargs.pop("allow_redirects", True) |
| 774 | stream = kwargs.get("stream") |
| 775 | hooks = request.hooks |
| 776 | |
| 777 | # Get the appropriate adapter to use |
| 778 | adapter = self.get_adapter(url=request.url) |
| 779 | |
| 780 | # Start time (approximately) of the request |
| 781 | start = preferred_clock() |
| 782 | |
| 783 | # Send the request |
| 784 | r = adapter.send(request, **kwargs) |
| 785 | |
| 786 | # Total elapsed time of the request (approximately) |
| 787 | elapsed = preferred_clock() - start |
| 788 | r.elapsed = timedelta(seconds=elapsed) |
| 789 | |
| 790 | # Response manipulation hooks |
| 791 | r = dispatch_hook("response", hooks, r, **kwargs) |
| 792 | |
| 793 | # Persist cookies |
| 794 | if r.history: |
| 795 | # If the hooks create history then we want those cookies too |
| 796 | for resp in r.history: |
| 797 | extract_cookies_to_jar(self.cookies, resp.request, resp.raw) |
| 798 | |
| 799 | extract_cookies_to_jar(self.cookies, request, r.raw) |
| 800 | |
| 801 | # Resolve redirects if allowed. |
| 802 | if allow_redirects: |
| 803 | # Redirect resolving generator. |
| 804 | gen = self.resolve_redirects(r, request, **kwargs) |
| 805 | history = [resp for resp in gen] |
| 806 | else: |
| 807 | history = [] |
| 808 | |
| 809 | # Shuffle things around if there's history. |