exceptions.md
This file
Path
docs/exceptions.md
172 lines · 3.5 KiB · Markdown
Last changed by
`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af
History of this fileTake it
The walk stopped after 200 commits: lines older than f540bd0 point at it.
Expand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 1–13why, one step back1# Exceptions23## Request and Response exceptions45The most important exception classes in HTTPX are `RequestError` and `HTTPStatusError`.67The `RequestError` class is a superclass that encompasses any exception that occurs8while issuing an HTTP request. These exceptions include a `.request` attribute.910```python11try:12 response = httpx.get("https://www.example.com/")13except httpx.RequestError as exc:Update exceptions.md (#1432)Gerhard van Andelbefore adoption3c89b91
line 14why, one step back14 print(f"An error occurred while requesting {exc.request.url!r}.")Expand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 15–47why, one step back15```1617The `HTTPStatusError` class is raised by `response.raise_for_status()` on 4xx and 5xx responses.18These exceptions include both a `.request` and a `.response` attribute.1920```python21response = httpx.get("https://www.example.com/")22try:23 response.raise_for_status()24except httpx.HTTPStatusError as exc:25 print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")26```2728There is also a base class `HTTPError` that includes both of these categories, and can be used29to catch either failed requests, or 4xx and 5xx responses.3031You can either use this base class to catch both categories...3233```python34try:35 response = httpx.get("https://www.example.com/")36 response.raise_for_status()37except httpx.HTTPError as exc:38 print(f"Error while requesting {exc.request.url!r}.")39```4041Or handle each case explicitly...4243```python44try:45 response = httpx.get("https://www.example.com/")46 response.raise_for_status()47except httpx.RequestError as exc:Update exceptions.md (#1432)Gerhard van Andelbefore adoption3c89b91
line 48why, one step back48 print(f"An error occurred while requesting {exc.request.url!r}.")Expand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 49–77why, one step back49except httpx.HTTPStatusError as exc:50 print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")51```5253---5455## The exception hierarchy5657* HTTPError58 * RequestError59 * TransportError60 * TimeoutException61 * ConnectTimeout62 * ReadTimeout63 * WriteTimeout64 * PoolTimeout65 * NetworkError66 * ConnectError67 * ReadError68 * WriteError69 * CloseError70 * ProtocolError71 * LocalProtocolError72 * RemoteProtocolError73 * ProxyError74 * UnsupportedProtocol75 * DecodingError76 * TooManyRedirects77 * HTTPStatusErrorInclude invalid url exception in docs (#1166)Tom Christiebefore adoption557ad70
line 78why, one step back78* InvalidURLExpand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 79–150why, one step back79* CookieConflict80* StreamError81 * StreamConsumed82 * ResponseNotRead83 * RequestNotRead84 * ResponseClosed8586---8788## Exception classes8990::: httpx.HTTPError91 :docstring:9293::: httpx.RequestError94 :docstring:9596::: httpx.TransportError97 :docstring:9899::: httpx.TimeoutException100 :docstring:101102::: httpx.ConnectTimeout103 :docstring:104105::: httpx.ReadTimeout106 :docstring:107108::: httpx.WriteTimeout109 :docstring:110111::: httpx.PoolTimeout112 :docstring:113114::: httpx.NetworkError115 :docstring:116117::: httpx.ConnectError118 :docstring:119120::: httpx.ReadError121 :docstring:122123::: httpx.WriteError124 :docstring:125126::: httpx.CloseError127 :docstring:128129::: httpx.ProtocolError130 :docstring:131132::: httpx.LocalProtocolError133 :docstring:134135::: httpx.RemoteProtocolError136 :docstring:137138::: httpx.ProxyError139 :docstring:140141::: httpx.UnsupportedProtocol142 :docstring:143144::: httpx.DecodingError145 :docstring:146147::: httpx.TooManyRedirects148 :docstring:149150::: httpx.HTTPStatusErrorInclude invalid url exception in docs (#1166)Tom Christiebefore adoption557ad70
lines 151–153why, one step back151 :docstring:152153::: httpx.InvalidURLExpand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 154–164why, one step back154 :docstring:155156::: httpx.CookieConflict157 :docstring:158159::: httpx.StreamError160 :docstring:161162::: httpx.StreamConsumed163 :docstring:164`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af
line 165why, one step back165::: httpx.StreamClosedExpand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 166–167why, one step back166 :docstring:167`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af
line 168why, one step back168::: httpx.ResponseNotReadExpand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
lines 169–170why, one step back169 :docstring:170`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af
line 171why, one step back171::: httpx.RequestNotReadExpand client docstrings (#1152)Felix Hildénbefore adoptionf540bd0
line 172why, one step back172 :docstring: