MCPcopy
hub / github.com/psf/requests / raise_for_status

Method raise_for_status

src/requests/models.py:1140–1167  ·  view source on GitHub ↗

Raises :class:`HTTPError`, if one occurred.

(self)

Source from the content-addressed store, hash-verified

1138 return resolved_links
1139
1140 def raise_for_status(self) -> None:
1141 """Raises :class:`HTTPError`, if one occurred."""
1142
1143 http_error_msg = ""
1144 if isinstance(self.reason, bytes):
1145 # We attempt to decode utf-8 first because some servers
1146 # choose to localize their reason strings. If the string
1147 # isn't utf-8, we fall back to iso-8859-1 for all other
1148 # encodings. (See PR #3538)
1149 try:
1150 reason = self.reason.decode("utf-8")
1151 except UnicodeDecodeError:
1152 reason = self.reason.decode("iso-8859-1")
1153 else:
1154 reason = self.reason
1155
1156 if 400 <= self.status_code < 500:
1157 http_error_msg = (
1158 f"{self.status_code} Client Error: {reason} for url: {self.url}"
1159 )
1160
1161 elif 500 <= self.status_code < 600:
1162 http_error_msg = (
1163 f"{self.status_code} Server Error: {reason} for url: {self.url}"
1164 )
1165
1166 if http_error_msg:
1167 raise HTTPError(http_error_msg, response=self)
1168
1169 def close(self) -> None:
1170 """Releases the connection back to the pool. Once this method has been

Calls 1

HTTPErrorClass · 0.85