utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:open-mic 作者: cosmir 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号