Skip to main content
added 14 characters in body
Source Link
Falko
  • 18.2k
  • 14
  • 65
  • 119

Actually, there are much more exceptions that requests.get() can generate than just ConnectionError. Here are some I've seen in production:

from requests import ReadTimeout, ConnectTimeout, HTTPError, Timeout, ConnectionError   try: r = requests.get(url, timeout=6.0) except (ConnectTimeout, HTTPError, ReadTimeout, Timeout, ConnectionError): continue 

Actually, there are much more exceptions that requests.get() can generate than just ConnectionError. Here are some I've seen in production:

from requests import ReadTimeout, ConnectTimeout, HTTPError, Timeout, ConnectionError try: r = requests.get(url, timeout=6.0) except (ConnectTimeout, HTTPError, ReadTimeout, Timeout, ConnectionError): continue 

Actually, there are much more exceptions that requests.get() can generate than just ConnectionError. Here are some I've seen in production:

from requests import ReadTimeout, ConnectTimeout, HTTPError, Timeout, ConnectionError   try: r = requests.get(url, timeout=6.0) except (ConnectTimeout, HTTPError, ReadTimeout, Timeout, ConnectionError): continue 
Source Link
kravietz
  • 11.4k
  • 2
  • 40
  • 30

Actually, there are much more exceptions that requests.get() can generate than just ConnectionError. Here are some I've seen in production:

from requests import ReadTimeout, ConnectTimeout, HTTPError, Timeout, ConnectionError try: r = requests.get(url, timeout=6.0) except (ConnectTimeout, HTTPError, ReadTimeout, Timeout, ConnectionError): continue