Home

Published

- 1 min read

python check if there is internet

img of python check if there is internet

The solution for this is noted below

python check if there is internet

Solution

   try:
    import httplib  # python < 3.0
except:
    import http.client as httplib


def have_internet():
    conn = httplib.HTTPSConnection("8.8.8.8", timeout=5)
    try:
        conn.request("HEAD", "/")
        return True
    except Exception:
        return False
    finally:
        conn.close()

Try other methods by searching on the site. That is if this doesn’t work