Home / Class/ Response Class — requests Architecture

Response Class — requests Architecture

Architecture documentation for the Response class in models.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  eb32847e_3797_d01a_6e44_345e9ea7e251["Response"]
  461bc6e0_32e7_8eab_ec87_7226e7be0d13["models.py"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|defined in| 461bc6e0_32e7_8eab_ec87_7226e7be0d13
  b47cdd7b_1bee_c465_e1f8_c3fa479afe6c["__init__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| b47cdd7b_1bee_c465_e1f8_c3fa479afe6c
  115c3974_b311_63ed_92dc_b9941ed80bac["__enter__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 115c3974_b311_63ed_92dc_b9941ed80bac
  49ceb938_bba9_0e58_f8e6_7676b9728120["__exit__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 49ceb938_bba9_0e58_f8e6_7676b9728120
  2cae4af2_31fc_8553_dd57_62d22ee2e7c7["__getstate__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 2cae4af2_31fc_8553_dd57_62d22ee2e7c7
  df32e078_271f_6e5d_1714_28dd0a2742cc["__setstate__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| df32e078_271f_6e5d_1714_28dd0a2742cc
  0a34a25b_0807_4992_7046_f655aa8d8d10["__repr__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 0a34a25b_0807_4992_7046_f655aa8d8d10
  688401b6_9092_b23f_4739_e55b00c176e1["__bool__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 688401b6_9092_b23f_4739_e55b00c176e1
  d4909b60_dbae_1fda_4666_20e395b55706["__nonzero__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| d4909b60_dbae_1fda_4666_20e395b55706
  89ebbd87_2a88_90dc_1402_eb6ff1e8f6fc["__iter__()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| 89ebbd87_2a88_90dc_1402_eb6ff1e8f6fc
  aa4a4768_e39e_c956_e629_331246c4b8df["ok()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| aa4a4768_e39e_c956_e629_331246c4b8df
  c8c27d14_4fd4_ecf3_b276_22b2fb768325["is_redirect()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| c8c27d14_4fd4_ecf3_b276_22b2fb768325
  fce2fe1a_e07c_180b_a87b_6241b04345fd["is_permanent_redirect()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| fce2fe1a_e07c_180b_a87b_6241b04345fd
  d723c9c6_8627_9b28_a441_3b8f522e7521["next()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251 -->|method| d723c9c6_8627_9b28_a441_3b8f522e7521

Relationship Graph

Source Code

src/requests/models.py lines 642–1041

class Response:
    """The :class:`Response <Response>` object, which contains a
    server's response to an HTTP request.
    """

    __attrs__ = [
        "_content",
        "status_code",
        "headers",
        "url",
        "history",
        "encoding",
        "reason",
        "cookies",
        "elapsed",
        "request",
    ]

    def __init__(self):
        self._content = False
        self._content_consumed = False
        self._next = None

        #: Integer Code of responded HTTP Status, e.g. 404 or 200.
        self.status_code = None

        #: Case-insensitive Dictionary of Response Headers.
        #: For example, ``headers['content-encoding']`` will return the
        #: value of a ``'Content-Encoding'`` response header.
        self.headers = CaseInsensitiveDict()

        #: File-like object representation of response (for advanced usage).
        #: Use of ``raw`` requires that ``stream=True`` be set on the request.
        #: This requirement does not apply for use internally to Requests.
        self.raw = None

        #: Final URL location of Response.
        self.url = None

        #: Encoding to decode with when accessing r.text.
        self.encoding = None

        #: A list of :class:`Response <Response>` objects from
        #: the history of the Request. Any redirect responses will end
        #: up here. The list is sorted from the oldest to the most recent request.
        self.history = []

        #: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
        self.reason = None

        #: A CookieJar of Cookies the server sent back.
        self.cookies = cookiejar_from_dict({})

        #: The amount of time elapsed between sending the request
        #: and the arrival of the response (as a timedelta).
        #: This property specifically measures the time taken between sending
        #: the first byte of the request and finishing parsing the headers. It
        #: is therefore unaffected by consuming the response content or the
        #: value of the ``stream`` keyword argument.
        self.elapsed = datetime.timedelta(0)

        #: The :class:`PreparedRequest <PreparedRequest>` object to which this
        #: is a response.
        self.request = None

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self.close()

    def __getstate__(self):
        # Consume everything; accessing the content attribute makes
        # sure the content has been fully read.
        if not self._content_consumed:
            self.content

        return {attr: getattr(self, attr, None) for attr in self.__attrs__}

    def __setstate__(self, state):
        for name, value in state.items():

Domain

Frequently Asked Questions

What is the Response class?
Response is a class in the requests codebase, defined in src/requests/models.py.
Where is Response defined?
Response is defined in src/requests/models.py at line 642.

Analyze Your Own Codebase

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

Try Supermodel Free