python 2.7 - How to check if .tar.gz archive corrupted after download? -
i use python 2.7.8 , request library download tar.gz archives usgs.gov site.
sometimes connection interrupted , not files uncompressed archive (but file not corrupted completely). use following code (a part of it) download data:
import requests import traceback def download_file(url, file_path): # note stream=true parameter r = requests.get(url, timeout=120, stream=true) open(file_path, 'wb') f: chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) return file_path try: download_file(url, scene_path) except: traceback.print_exc() if os.path.isfile(scene_path): os.remove(scene_path) print u'<= del'
how check if *.tar.gz archive corrupted after download?
Comments
Post a Comment