Home / Function/ build_response() — requests Function Reference

build_response() — requests Function Reference

Architecture documentation for the build_response() function in adapters.py from the requests codebase.

Function python CoreAPI SessionLifecycle calls 2 called by 1

Entity Profile

Dependency Diagram

graph TD
  7086c4f7_aa89_192d_ccbb_8bfa981ed237["build_response()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91["HTTPAdapter"]
  7086c4f7_aa89_192d_ccbb_8bfa981ed237 -->|defined in| 5fdf5d52_8295_768a_e20f_c6cefb721b91
  66fc1563_b020_b369_a505_bc9abe7cf66d["send()"]
  66fc1563_b020_b369_a505_bc9abe7cf66d -->|calls| 7086c4f7_aa89_192d_ccbb_8bfa981ed237
  9ab5b77a_1e93_5426_2b6e_540e378c20b4["get_encoding_from_headers()"]
  7086c4f7_aa89_192d_ccbb_8bfa981ed237 -->|calls| 9ab5b77a_1e93_5426_2b6e_540e378c20b4
  55052edd_2a43_f298_b8d3_9fb1f2641e84["extract_cookies_to_jar()"]
  7086c4f7_aa89_192d_ccbb_8bfa981ed237 -->|calls| 55052edd_2a43_f298_b8d3_9fb1f2641e84
  style 7086c4f7_aa89_192d_ccbb_8bfa981ed237 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/adapters.py lines 338–373

    def build_response(self, req, resp):
        """Builds a :class:`Response <requests.Response>` object from a urllib3
        response. This should not be called from user code, and is only exposed
        for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`

        :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
        :param resp: The urllib3 response object.
        :rtype: requests.Response
        """
        response = Response()

        # Fallback to None if there's no status_code, for whatever reason.
        response.status_code = getattr(resp, "status", None)

        # Make headers case-insensitive.
        response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))

        # Set encoding.
        response.encoding = get_encoding_from_headers(response.headers)
        response.raw = resp
        response.reason = response.raw.reason

        if isinstance(req.url, bytes):
            response.url = req.url.decode("utf-8")
        else:
            response.url = req.url

        # Add new cookies from the server.
        extract_cookies_to_jar(response.cookies, req, resp)

        # Give the Response some context.
        response.request = req
        response.connection = self

        return response

Domain

Subdomains

Called By

Frequently Asked Questions

What does build_response() do?
build_response() is a function in the requests codebase, defined in src/requests/adapters.py.
Where is build_response() defined?
build_response() is defined in src/requests/adapters.py at line 338.
What does build_response() call?
build_response() calls 2 function(s): extract_cookies_to_jar, get_encoding_from_headers.
What calls build_response()?
build_response() is called by 1 function(s): send.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free