MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / APIResponse

Class APIResponse

py/selenium/webdriver/common/api_request_context.py:52–100  ·  view source on GitHub ↗

Represents an HTTP response from an API request. Attributes: status: HTTP status code. status_text: HTTP status text. headers: Response headers as a dict. url: The request URL.

Source from the content-addressed store, hash-verified

50
51
52class APIResponse:
53 """Represents an HTTP response from an API request.
54
55 Attributes:
56 status: HTTP status code.
57 status_text: HTTP status text.
58 headers: Response headers as a dict.
59 url: The request URL.
60 """
61
62 def __init__(self, status: int, status_text: str, headers: dict[str, str], url: str, body: bytes) -> None:
63 self.status = status
64 self.status_text = status_text
65 self.headers = headers
66 self.url = url
67 self._body = body
68
69 @property
70 def ok(self) -> bool:
71 """Whether the response status is in the 200-299 range."""
72 return 200 <= self.status <= 299
73
74 def json(self) -> Any:
75 """Parse the response body as JSON.
76
77 Returns:
78 The parsed JSON object.
79 """
80 return json.loads(self._body)
81
82 def text(self) -> str:
83 """Decode the response body as UTF-8 text.
84
85 Returns:
86 The response body as a string.
87 """
88 return self._body.decode("utf-8")
89
90 def body(self) -> bytes:
91 """Return the raw response body bytes.
92
93 Returns:
94 The response body as bytes.
95 """
96 return self._body
97
98 def dispose(self) -> None:
99 """Free the response body memory."""
100 self._body = b""
101
102
103def _cookie_matches(cookie: Cookie, url: str, default_domain: str = "") -> bool:

Callers 14

test_ok_true_for_2xxFunction · 0.90
test_json_parsingFunction · 0.90
test_json_invalid_raisesFunction · 0.90
test_text_decodingFunction · 0.90
test_body_returns_bytesFunction · 0.90
test_dispose_clears_bodyFunction · 0.90
test_message_formatFunction · 0.90
test_response_accessibleFunction · 0.90
test_is_exceptionFunction · 0.90

Calls

no outgoing calls

Tested by 13

test_ok_true_for_2xxFunction · 0.72
test_json_parsingFunction · 0.72
test_json_invalid_raisesFunction · 0.72
test_text_decodingFunction · 0.72
test_body_returns_bytesFunction · 0.72
test_dispose_clears_bodyFunction · 0.72
test_message_formatFunction · 0.72
test_response_accessibleFunction · 0.72
test_is_exceptionFunction · 0.72