openreview-py icon indicating copy to clipboard operation
openreview-py copied to clipboard

catch all requests exceptions

Open melisabok opened this issue 7 years ago • 0 comments

source: https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module

url='http://www.google.com/blahblah'

try:
    r = requests.get(url,timeout=3)
    r.raise_for_status()
except requests.exceptions.HTTPError as errh:
    print ("Http Error:",errh)
except requests.exceptions.ConnectionError as errc:
    print ("Error Connecting:",errc)
except requests.exceptions.Timeout as errt:
    print ("Timeout Error:",errt)
except requests.exceptions.RequestException as err:
    print ("OOps: Something Else",err)

Http Error: 404 Client Error: Not Found for url: http://www.google.com/blahblah

melisabok avatar Jan 30 '18 16:01 melisabok