Here is my code
import requests
ping = requests.get('http://example.com')
ping.status_code
if ping.status_code==200:
print ("Online")
else:
print ("Offline")
It pings http://example.com
. When the website is online it successfully prints Online
. when the website is offline, I want it to print Offline
but instead it is showing me a huge error message ends with this line
Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd3f17372e8>: Failed to establish a new connection: [Errno -2] Name or service not known',))
How can I fix it to successfully print Offline
if the website is offline?