File: internet-urllib3.py

package info (click to toggle)
offlineimap3 0.0~git20210225.1e7ef9e%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,328 kB
  • sloc: python: 7,974; sh: 548; makefile: 81
file content (19 lines) | stat: -rw-r--r-- 462 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python

import urllib3
import certifi

def isInternetConnected(url="www.ietf.org"):
  result = False
  http = urllib3.PoolManager(
    cert_reqs='CERT_REQUIRED', # Force certificate check.
    ca_certs=certifi.where(),  # Path to the Certifi bundle.
  )
  try:
    r = http.request('HEAD', 'https://' + url)
    result = True
  except Exception as e:  # urllib3.exceptions.SSLError
    result = False
  return result

print(isInternetConnected())