If you are already using the requests library, it is convenient to also use it here:
import requests
try:
requests.get("https://healthchecks.lavenderfive.com/ping/your-uuid-here", timeout=10)
except requests.RequestException as e:
# Log ping failure here...
print("Ping failed: %s" % e)
Otherwise, you can use the urllib.request module from Python 3 standard library:
import socket
import urllib.request
try:
urllib.request.urlopen("https://healthchecks.lavenderfive.com/ping/your-uuid-here", timeout=10)
except socket.error as e:
# Log ping failure here...
print("Ping failed: %s" % e)
You can include additional diagnostic information in the request body (for POST requests):
# Passing diagnostic information in the POST body:
import requests
requests.post("https://healthchecks.lavenderfive.com/ping/your-uuid-here", data="temperature=-7")