You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
776 B

  1. # Python
  2. If you are already using the requests library, it is convenient to also use it here:
  3. ```python
  4. import requests
  5. try:
  6. requests.get("PING_URL", timeout=10)
  7. except requests.RequestException as e:
  8. # Log ping failure here...
  9. print("Ping failed: %s" % e)
  10. ```
  11. Otherwise, you can use the urllib module from Python 3 standard libary:
  12. ```python
  13. import socket
  14. import urllib.request
  15. try:
  16. urllib.request.urlopen("PING_URL", timeout=10)
  17. except socket.error as e:
  18. # Log ping failure here...
  19. print("Ping failed: %s" % e)
  20. ```
  21. You can include additional diagnostic information in the in the request body (for POST requests):
  22. ```python
  23. # Passing diagnostic information in the POST body:
  24. import requests
  25. requests.post("PING_URL", data="temperature=-7")
  26. ```