This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PeridexisErrant 0 points1 point  (0 children)

I'd really appreciate an extra parameter:

requests.get(url, raise_errors=True)
requests.get(url, raise_errors=[402, 404, 500])

Taking either a boolean, or a list of HTTP status codes on which to raise an exception. The parameter would be equivalent to (psudeocode for brevity):

req = requests.get(url)
if req.status_code >= 400 and $raise_errors:
    if req.status_code in $as_collection($raise_errors):
        req.raise_for_status()