utils.py 文件源码

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

项目:AutomatorX 作者: xiaoyaojjian 项目源码 文件源码
def http_download(url, target_path):
    """Download file to local
    Args:
        - url(string): url request path
        - target_path(string): download destination

    Raises:
        IOError
        urllib2.URLError
    """
    try:
        resp = urllib2.urlopen(url)
    except urllib2.URLError, e:
        if not hasattr(e, 'code'):
            raise
        resp = e
    if resp.code != 200:
        raise IOError("Request url(%s) expect 200 but got %d" %(url, resp.code))

    with open(target_path, 'wb') as f:
        shutil.copyfileobj(resp, f)
    return target_path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号