1
0
mirror of https://github.com/OfflineIMAP/offlineimap.git synced 2024-06-28 07:40:51 +02:00
offlineimap/contrib/internet-urllib3.py
Chris Coleman 99b06ef47e Secure HTTPS test internet is connected.
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-05-04 22:25:22 +02:00

20 lines
461 B
Python

#!/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()