How to handle exceptions with python library requests? For example how to check is PC connected to internet?
When I try
try:
requests.get('http://www.google.com')
except ConnectionError:
# handle the exception
it gives me error name ConnectionError is not defined
Assuming you did
import requests, you wantrequests.ConnectionError.ConnectionErroris an exception defined byrequests. See the API documentation here.Thus the code should be:
The original link to the Python v2 API documentation from the original answer no longer works.