From 1980806fc507f68339c979c4287e31a857370908 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:45:50 -0400 Subject: [PATCH] Fix bandit and doc failures --- acstools/focus_diverse_epsfs.py | 12 +++++++++--- doc/source/index.rst | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/acstools/focus_diverse_epsfs.py b/acstools/focus_diverse_epsfs.py index 01d6570..c455a21 100644 --- a/acstools/focus_diverse_epsfs.py +++ b/acstools/focus_diverse_epsfs.py @@ -103,7 +103,7 @@ def _validate_acs_ipsoot(line): return isinstance(line, str) and len(line) == 9 and line.startswith("j") -def psf_retriever(ipsoot, download_location): +def psf_retriever(ipsoot, download_location, timeout=60): """Function to query API on AWS API Gateway for the ePSF FITS file that corresponds to a given image rootname. @@ -122,6 +122,9 @@ def psf_retriever(ipsoot, download_location): Directory name where the file will be downloaded to. It must exist and you must have write permission to it. + timeout : float + Seconds before query timeout. + Returns ------- desired_filename : str or `None` @@ -147,7 +150,7 @@ def psf_retriever(ipsoot, download_location): # send up post request with ipsoot event myobj = {'ipsoot': ipsoot} - result = requests.post(api_url, json=myobj, auth=auth) + result = requests.post(api_url, json=myobj, auth=auth, timeout=timeout) if not result.ok: LOG.error("Query failed: %d %s" % (result.status_code, result.reason)) @@ -159,6 +162,9 @@ def psf_retriever(ipsoot, download_location): # grab url from result url = result.text[1:-1] + if not url.startswith("http"): + LOG.error("URL is not HTTP.") + return with urlopen(url) as remotefile: # determine readable name for file content_disposition = remotefile.info()['Content-Disposition'] @@ -175,7 +181,7 @@ def psf_retriever(ipsoot, download_location): return # download file - urlretrieve(url, filename=desired_filename) + urlretrieve(url, filename=desired_filename) # nosec (already checked above) return desired_filename diff --git a/doc/source/index.rst b/doc/source/index.rst index 7fd2c55..49448f2 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -42,7 +42,7 @@ To install the development version of this package:: satdet findsat_mrt polarization_tools - focus_diverse_epsf + focus_diverse_epsfs utils_calib ******************