0

For a small script i have to test if a server i'm trying to download a file from is available to prevent errors. I Tried pinging the server (school website), but pinging is not allowed so i wouldn't get any responses. I could try pinging google.com, but this only checks the client side of the connection. pinging also doesn't work when i'm at school because of the same reason.

Code i am using now:

import subprocess

try:
    subprocess.check_output(["ping", "-n", "1", "-w", "1000", "google.com"])
except subprocess.CalledProcessError:
    # Code to run when no internet connection is available
    return False

I was wondering if there's another way to check server availability without using ping, but by still using python. For the solutions I was able to find only i couldn't find a way to implement it in python (by my experience)

  • 2
    See this question: [How do you send a HEAD HTTP request in Python 2?](https://stackoverflow.com/questions/107405/how-do-you-send-a-head-http-request-in-python-2) – Peter Wood Nov 22 '16 at 09:40
  • Had a feeling an answer was available, but couldn't find it and i know why now. Thanks anyway –  Nov 22 '16 at 09:53

0 Answers0