# raise_for_status()

*noun*

say it: **“RAYZ for STAT-us”** **/ˈreɪz fɔr ˈstætəs/**

A method on a requests response that raises an error when the server answered with a failure code, from 400 to 599.

## What does **raise_for_status()** do?

**raise_for_status()** is a method on a `requests` response that raises an `HTTPError` when the status code is from
400 to 599, and does nothing otherwise, so a failed request can't pass as a good one.

```python
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()   # HTTPError: 404 Client Error: Not Found for url: ...
forecast = response.json()    # reached only when the request worked
```

## In a sentence

- “Put **raise_for_status()** before json(), so an error page is never read as data.”
- “Calling **raise_for_status()** turned the 404 into an error the script could catch.”

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/raise-for-status
