Is there any reason to prioritize raising/catching requests.exceptions.HTTPError over requests.HTTPError or requests.HTTPError over requests.exceptions.HTTPError?
These two are the same class (As can be seen by reading the source code and by witnessing True is the output of requests.exceptions.HTTPError is requests.HTTPError), yet I ask this question as they both exist.
They both do the same thing. There's no reason to prioritize one over the other.
Try this experiment:
try:
r = requests.get('http://www.google.com/nothere')
r.raise_for_status()
except requests.exceptions.HTTPError as e:
print(e.response.text)
And then:
try:
r = requests.get('http://www.google.com/nothere')
r.raise_for_status()
except requests.HTTPError as e:
print(e.response.text)
You'll get the same thing each time:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
[***]
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/nothere</code> was not found on this server.
<ins>That’s all we know.</ins>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With