Home / Function/ raise_for_status() — requests Function Reference

raise_for_status() — requests Function Reference

Architecture documentation for the raise_for_status() function in models.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  0ff85151_95cf_f245_0e4f_aea80330b552["raise_for_status()"]
  eb32847e_3797_d01a_6e44_345e9ea7e251["Response"]
  0ff85151_95cf_f245_0e4f_aea80330b552 -->|defined in| eb32847e_3797_d01a_6e44_345e9ea7e251
  aa4a4768_e39e_c956_e629_331246c4b8df["ok()"]
  aa4a4768_e39e_c956_e629_331246c4b8df -->|calls| 0ff85151_95cf_f245_0e4f_aea80330b552
  style 0ff85151_95cf_f245_0e4f_aea80330b552 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/models.py lines 1001–1028

    def raise_for_status(self):
        """Raises :class:`HTTPError`, if one occurred."""

        http_error_msg = ""
        if isinstance(self.reason, bytes):
            # We attempt to decode utf-8 first because some servers
            # choose to localize their reason strings. If the string
            # isn't utf-8, we fall back to iso-8859-1 for all other
            # encodings. (See PR #3538)
            try:
                reason = self.reason.decode("utf-8")
            except UnicodeDecodeError:
                reason = self.reason.decode("iso-8859-1")
        else:
            reason = self.reason

        if 400 <= self.status_code < 500:
            http_error_msg = (
                f"{self.status_code} Client Error: {reason} for url: {self.url}"
            )

        elif 500 <= self.status_code < 600:
            http_error_msg = (
                f"{self.status_code} Server Error: {reason} for url: {self.url}"
            )

        if http_error_msg:
            raise HTTPError(http_error_msg, response=self)

Domain

Subdomains

Called By

Frequently Asked Questions

What does raise_for_status() do?
raise_for_status() is a function in the requests codebase, defined in src/requests/models.py.
Where is raise_for_status() defined?
raise_for_status() is defined in src/requests/models.py at line 1001.
What calls raise_for_status()?
raise_for_status() is called by 1 function(s): ok.

Analyze Your Own Codebase

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

Try Supermodel Free