import urllib.request, socket socket.setdefaulttimeout(8) for url, name in [("https://remoteok.com/api", "remoteok"), ("https://www.google.com", "google")]: try: urllib.request.urlopen(url) print(name, "OK") except Exception as e: print(name, "FAIL ->", type(e).__name__)