def check_connection(default='http://google.com', timeout=1):
"""Test the internet connection.
Parameters
----------
default : str
URL to test; defaults to a Google IP address.
timeout : number
Time in seconds to wait before giving up.
Returns
-------
success : bool
True if appears to be online, else False
"""
success = True
try:
surl = urlparse.quote(default, safe=':./')
urlrequest.urlopen(surl, timeout=timeout)
except urlerror.URLError as derp:
success = False
logger.debug("Network unreachable: {}".format(derp))
return success
评论列表
文章目录