Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise_for_status now raises an exception for 1xx and 3xx responses #2126

Closed
remi-dupre opened this issue Mar 14, 2022 · 2 comments · Fixed by #2159
Closed

raise_for_status now raises an exception for 1xx and 3xx responses #2126

remi-dupre opened this issue Mar 14, 2022 · 2 comments · Fixed by #2159
Labels
docs Changes to the documentation good first issue Good for newcomers

Comments

@remi-dupre
Copy link

Hi!

I've just noticed that response.raise_for_status() now raises an exception for 1xx and 3xx requests. I don't think it was the case before (namely with version 0.18) and the documentation doesn't seem to have been updated here: https://www.python-httpx.org/exceptions/

The HTTPStatusError class is raised by response.raise_for_status() on 4xx and 5xx responses.

Steps to reproduce (even though I think this is an intentional behavior, the doc is just not up to date?)

import httpx
url_301 = "https://stat.pagesjaunes.fr/redirect?target=ETvxvbcLWawl69YzLe_Ph4vo03E_Yj6_Jt1_EvjjbHFaCE3c9RGLEg==&v=2.0&p1=1&p2=1&p3=&p4=RESEAUSOC-SITE-LVS-GRATUIT&p5=LR&p6=1361647273529289141447273529289&p7=06486910&p8="
httpx.get(url_301, follow_redirects=False).raise_for_status()
@florimondmanca
Copy link
Member

florimondmanca commented Mar 14, 2022

@remi-dupre Hey, indeed, looking at the blame this seems to come from #1854, the documentation had not been updated at the time, PR description reads:

The .raise_for_status() method now raises on any response except 2xx.

I assume we could change the docs to read... ?

The HTTPStatusError class is raised by response.raise_for_status() on any response except 2xx.

@florimondmanca florimondmanca added the docs Changes to the documentation label Mar 14, 2022
@tomchristie
Copy link
Member

Yup, seconding @florimondmanca here.
Nice simple docs fix if anyone would like to take it on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Changes to the documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants