Skip to content
Myr

Display URL as part of HTTP error messages

Before adoption: this commit came in with the history the project adopted, so no landing records it.

It seems convenient to include the URL in the error message in case you get an unexpected error. E.g.: In [1]: import requests In [2]: resp = requests.get('http://www.google.com/eofdfdfdfdfd') In [3]: resp Out[3]: <Response [404]> In [4]: resp.raise_for_status() --------------------------------------------------------------------------- HTTPError Traceback (most recent call last) <ipython-input-4-00e7077cfb5b> in <module>() ----> 1 resp.raise_for_status() /Users/marca/dev/git-repos/requests/requests/models.py in raise_for_status(self) 835 836 if http_error_msg: --> 837 raise HTTPError(http_error_msg, response=self) 838 839 def close(self): HTTPError: 404 Client Error: Not Found for url: http://www.google.com/eofdfdfdfdfd

authored by Marc Abramowitz · committed by Marc Abramowitz · parent 9bbab33 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:requests/models.py+2 added-2 removed
826 unmodified lines
827828 http_error_msg = ''829830 if 400 <= self.status_code < 500:831 http_error_msg = '%s Client Error: %s' % (self.status_code, self.reason)831 http_error_msg = '%s Client Error: %s for url: %s' % (self.status_code, self.reason, self.url)832833 elif 500 <= self.status_code < 600:834 http_error_msg = '%s Server Error: %s' % (self.status_code, self.reason)834 http_error_msg = '%s Server Error: %s for url: %s' % (self.status_code, self.reason, self.url)835836 if http_error_msg:837 raise HTTPError(http_error_msg, response=self)838
10 unmodified lines