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.

36 lines
882 B

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