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 ConnectionError
try:
   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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)