From ff1848481cec841d895a7bcef7119a354c4c1791 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Feb 13 2020 05:16:30 +0000 Subject: Raise early if requests fail. This prevents weird exceptions about BZ2/LZMA compression failing, when it's really because of empty data. --- diff --git a/mdapi-get_repo_md b/mdapi-get_repo_md index 51365d7..bfcde0a 100755 --- a/mdapi-get_repo_md +++ b/mdapi-get_repo_md @@ -153,6 +153,7 @@ def list_branches(status='Active'): ''' url = PKGDB2_URL + f'api/collections?clt_status={status}' response = requests.get(url, verify=PKGDB2_VERIFY) + response.raise_for_status() data = response.json() return data['collections'] @@ -160,6 +161,7 @@ def list_branches(status='Active'): def download_db(name, repomd_url, archive): print(f'{name.ljust(padding)} Downloading file: {repomd_url} to {archive}') response = requests.get(repomd_url, verify=DL_VERIFY) + response.raise_for_status() with open(archive, 'wb') as stream: stream.write(response.content) @@ -360,7 +362,7 @@ def process_repo(tupl): url, name = repo repomd_url = url + '/repomd.xml' response = requests.get(repomd_url, verify=DL_VERIFY) - if not bool(response): + if not response: print(f'{name.ljust(padding)} !! Failed to get {repomd_url!r} {response!r}') return