{"id":1004,"hash":"1c88a15822569a844985216747bc4addb307066df95d3943508299ef8dfcb3db","pattern":"Python requests exception handling","full_message":"How to handle exceptions with python library requests?\nFor example how to check is PC connected to internet?\n\nWhen I try \n\ntry:\n    requests.get('http://www.google.com')\nexcept ConnectionError:\n    # handle the exception\n\nit gives me error name ConnectionError is not defined","ecosystem":"pypi","package_name":"exception","package_version":null,"solution":"Assuming you did import requests, you want requests.ConnectionError. ConnectionError is an exception defined by requests. See the API documentation here.\n\nThus the code should be:\n\ntry:\n   requests.get('http://www.google.com')\nexcept requests.ConnectionError:\n   # handle the exception\n\nThe original link to the Python v2 API documentation from the original answer no longer works.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/9054820/python-requests-exception-handling","votes":68,"created_at":"2026-04-19T04:52:09.116389+00:00","updated_at":"2026-04-19T04:52:09.116389+00:00"}