From 40840e341b56b7505f1e29629cf49fdfce165687 Mon Sep 17 00:00:00 2001 From: Nick H <34072991+nickssl@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:28:54 -0800 Subject: [PATCH 1/2] Changed http to https --- pyspedas/projects/themis/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyspedas/projects/themis/config.py b/pyspedas/projects/themis/config.py index abb00763..a881fa3c 100644 --- a/pyspedas/projects/themis/config.py +++ b/pyspedas/projects/themis/config.py @@ -1,7 +1,7 @@ import os CONFIG = {'local_data_dir': 'themis_data/', - 'remote_data_dir': 'http://themis.ssl.berkeley.edu/data/themis/'} + 'remote_data_dir': 'https://themis.ssl.berkeley.edu/data/themis/'} # override local data directory with environment variables if os.environ.get('SPEDAS_DATA_DIR'): From b568d2d4572ed90eae6e715df14c77b1070bea2a Mon Sep 17 00:00:00 2001 From: Nick H <34072991+nickssl@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:39:18 -0800 Subject: [PATCH 2/2] Fixed bug, download.py will now reject responses from captive portals and will not replace existing cdf and netcdf files. In some cases with captive wifi portals, the wifi responds with 200-OK but the downloaded file is not the file requested by the user, it only contains some html code, usually asking the user to login into the system. Previously, this fake file could replace an already existing cdf file, and then it would be deleted since it cannot be loaded into tplot. This bug was fixed, and now download.py will reject the fake file before replacing any existing files. This only works for cdf and netcdf files. --- pyspedas/utilities/download.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pyspedas/utilities/download.py b/pyspedas/utilities/download.py index 5c848094..164fd7cd 100644 --- a/pyspedas/utilities/download.py +++ b/pyspedas/utilities/download.py @@ -225,7 +225,8 @@ def download_file( return None if needs_to_download_file: - ftmp = NamedTemporaryFile(delete=False) + froot, fsuffix = os.path.splitext(filename) + ftmp = NamedTemporaryFile(delete=False, suffix=fsuffix) with open(ftmp.name, "wb") as f: if text_only: @@ -241,13 +242,18 @@ def download_file( os.makedirs(os.path.dirname(filename)) # if the download was successful, copy to data directory - copy(ftmp.name, filename) + if check_downloaded_file(ftmp.name): + copy(ftmp.name, filename) + logging.info("Download complete: " + filename) + else: + logging.error("Download of '" + filename + "' failed. The temp file will be removed.") + logging.error("If the same file has been already downloaded previously, it might be possible to use that instead.") + # cleanup fsrc.close() ftmp.close() os.unlink(ftmp.name) # delete the temporary file - - logging.info("Download complete: " + filename) + # At this point, we check if the file can be opened. # If it cannot be opened, we delete the file and try again.