I see one of the methods in python uses raise_for_status()
:
def raise_for_status(self):
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 self.status_code, HTTPError(http_error_msg, response=self)
I want to add a try/except
block such that, I can handle the exception. However, it also raises the status code along with the exception.
Not sure, how can I capture the status code without modifying the existing code for rasei_for_status()