Python requests - Exception Type: ConnectionError - try: except does not work Python requests - Exception Type: ConnectionError - try: except does not work python python

Python requests - Exception Type: ConnectionError - try: except does not work


You should not exit your worker instance sys.exit(1)Furthermore you 're catching the wrong Error.

What you could do for for example is:

from requests.exceptions import ConnectionErrortry:   r = requests.get("http://example.com", timeout=0.001)except ConnectionError as e:    # This is the correct syntax   print e   r = "No response"

In this case your program will continue, setting the value of r which usually saves the response to any default value