From 247a2dbe7c26a1de8c4a763f3855dd8408d413b1 Mon Sep 17 00:00:00 2001 From: AdamTheisen Date: Wed, 28 Jan 2026 12:18:55 -0600 Subject: [PATCH] ENH: Update ARM data download code to catch errors if files are incorrectly listed and not available for download. --- act/discovery/arm.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/act/discovery/arm.py b/act/discovery/arm.py index a215716cdc..fc0e6053b9 100644 --- a/act/discovery/arm.py +++ b/act/discovery/arm.py @@ -6,6 +6,7 @@ import json import os import textwrap +import urllib.error import warnings from datetime import timedelta @@ -157,14 +158,19 @@ def download_arm_data(username, token, datastream, startdate, enddate, time=None if not os.path.isdir(output_dir): os.makedirs(output_dir) # create file and write bytes to file - with open(output_file, 'wb') as open_bytes_file: - data = urlopen(req_save).read() - if 'This data file is not available' in str(data): - print(fname + ' is not available for download') - continue - else: - print(f'[DOWNLOADING] {fname}') - open_bytes_file.write(data) + try: + with open(output_file, 'wb') as open_bytes_file: + data = urlopen(req_save).read() + if 'This data file is not available' in str(data): + print(fname + ' is not available for download') + continue + else: + print(f'[DOWNLOADING] {fname}') + open_bytes_file.write(data) + except urllib.error.HTTPError: + print('Unable to download file: ' + fname) + os.remove(output_file) + continue file_names.append(output_file) # Get ARM DOI and print it out doi = get_arm_doi(