2020-07-17 16:51:23 +03:00

736 B

Python

If you are already using the requests library, it's convenient to also use it here:

import requests

try:
    requests.get("PING_URL", timeout=10)
except requests.RequestException as e:
    # Log ping failure here...
    print("Ping failed: %s" % e)

Otherwise, you can use the urllib standard module.

# urllib with python 3.x:
import urllib.request
urllib.request.urlopen("PING_URL")
# urllib with python 2.x:
import urllib
urllib.urlopen("PING_URL")

You can include additional diagnostic information in the in the request body (for POST requests):

# Passing diagnostic information in the POST body:
import requests
requests.post("PING_URL", data="temperature=-7")