From 435d5b8392434141ecb53529b07bff2ab13f2431 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 11 Jun 2025 12:38:54 -0400 Subject: [PATCH 01/10] gaia: do not query server at load time. Includes regression test --- astroquery/gaia/core.py | 32 +++++----- astroquery/tests/test_imports.py | 101 +++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 astroquery/tests/test_imports.py diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 0ec17f2c6e..7c353c9691 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -55,7 +55,7 @@ def __init__(self, *, tap_plus_conn_handler=None, gaia_data_server='https://gea.esac.esa.int/', tap_server_context="tap-server", data_server_context="data-server", - verbose=False, show_server_messages=True): + verbose=False, show_server_messages=False): super(GaiaClass, self).__init__(url=gaia_tap_server, server_context=tap_server_context, tap_context="tap", @@ -1168,23 +1168,19 @@ def get_status_messages(self): """Retrieve the messages to inform users about the status of Gaia TAP """ - try: - sub_context = self.GAIA_MESSAGES - conn_handler = self._TapPlus__getconnhandler() - response = conn_handler.execute_tapget(sub_context, verbose=False) - if response.status == 200: - if isinstance(response, Iterable): - for line in response: - - try: - print(line.decode("utf-8").split('=', 1)[1]) - except ValueError as e: - print(e) - except IndexError: - print("Archive down for maintenance") - - except OSError: - print("Status messages could not be retrieved") + sub_context = self.GAIA_MESSAGES + conn_handler = self._TapPlus__getconnhandler() + response = conn_handler.execute_tapget(sub_context, verbose=False) + if response.status == 200: + if isinstance(response, Iterable): + for line in response: + + try: + print(line.decode("utf-8").split('=', 1)[1]) + except ValueError as e: + print(e) + except IndexError: + print("Archive down for maintenance") Gaia = GaiaClass() diff --git a/astroquery/tests/test_imports.py b/astroquery/tests/test_imports.py new file mode 100644 index 0000000000..85c0f921e0 --- /dev/null +++ b/astroquery/tests/test_imports.py @@ -0,0 +1,101 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +import sys +import importlib +import pytest +import socket +from unittest.mock import patch +from pytest_remotedata.disable_internet import no_internet +from pytest_remotedata.disable_internet import INTERNET_OFF + +# List of all astroquery modules to test +ASTROQUERY_MODULES = [ + 'astroquery.alma', + 'astroquery.astrometry_net', + 'astroquery.besancon', + 'astroquery.cadc', + 'astroquery.cosmosim', + 'astroquery.esa', + 'astroquery.esasky', + 'astroquery.eso', + 'astroquery.exoplanet_orbit_database', + 'astroquery.fermi', + 'astroquery.gaia', + 'astroquery.gama', + 'astroquery.gemini', + 'astroquery.heasarc', + 'astroquery.hitran', + 'astroquery.ipac.irsa.ibe', + 'astroquery.hips2fits', + 'astroquery.image_cutouts', + 'astroquery.imcce', + 'astroquery.ipac', + 'astroquery.ipac.irsa', + 'astroquery.ipac.irsa.irsa_dust', + 'astroquery.ipac.ned', + 'astroquery.ipac.nexsci.nasa_exoplanet_archive', + 'astroquery.jplhorizons', + 'astroquery.jplsbdb', + 'astroquery.jplspec', + 'astroquery.linelists', + 'astroquery.magpis', + 'astroquery.mast', + 'astroquery.mocserver', + 'astroquery.mpc', + 'astroquery.nasa_ads', + 'astroquery.nist', + 'astroquery.nvas', + 'astroquery.oac', + 'astroquery.ogle', + 'astroquery.open_exoplanet_catalogue', + 'astroquery.sdss', + 'astroquery.simbad', + 'astroquery.skyview', + 'astroquery.solarsystem', + 'astroquery.splatalogue', + 'astroquery.svo_fps', + 'astroquery.utils', + 'astroquery.vamdc', + 'astroquery.vo_conesearch', + 'astroquery.vizier', + 'astroquery.vsa', + 'astroquery.wfau', + 'astroquery.xmatch', +] + +class SocketTracker: + def __init__(self): + self.socket_attempts = [] + + def __call__(self, *args, **kwargs): + # Record the attempt + self.socket_attempts.append((args, kwargs)) + # Raise a clear error to indicate socket creation + raise RuntimeError("Socket creation attempted during import") + + +@pytest.mark.parametrize("module_name", ASTROQUERY_MODULES) +def test_no_http_calls_during_import(module_name): + """ + Test that importing astroquery modules does not make any remote calls. + + This is a regression test for 3343, and the error that raises is not + properly caught by the framework below, but that's an unrelated issue. + + This is the error shown if Gaia(show_server_messages=True) is called: + ``` + E TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union + ``` + """ + with no_internet(): + if module_name in sys.modules: + del sys.modules[module_name] + + tracker = SocketTracker() + with patch('socket.socket', tracker): + importlib.import_module(module_name) + + assert not tracker.socket_attempts, ( + f"Module {module_name} attempted to create {len(tracker.socket_attempts)} " + f"socket(s) during import:\n" + + "\n".join(f" - {args} {kwargs}" for args, kwargs in tracker.socket_attempts) + ) \ No newline at end of file From 3cbd794f0c86eb36cfdffaf4be27d250e8547ee4 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 11 Jun 2025 14:48:56 -0400 Subject: [PATCH 02/10] remove try/except clauses in more show messages, and set show_messages to false by default at import time --- astroquery/esa/euclid/core.py | 33 +++++++++++++++------------------ astroquery/esa/hubble/core.py | 19 ++++++++++--------- astroquery/esa/jwst/core.py | 19 ++++++++----------- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index cb4b120004..4068f3efb8 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -754,23 +754,20 @@ def get_status_messages(self, verbose=False): flag to display information about the process """ - try: - sub_context = self.EUCLID_MESSAGES - conn_handler = self._TapPlus__getconnhandler() - response = conn_handler.execute_tapget(sub_context, verbose=verbose) - if response.status == 200: - if isinstance(response, Iterable): - for line in response: - - try: - print(line.decode("utf-8").split('=', 1)[1]) - except ValueError as e: - print(e) - except IndexError: - print("Archive down for maintenance") - - except OSError: - print("Status messages could not be retrieved") + sub_context = self.EUCLID_MESSAGES + conn_handler = self._TapPlus__getconnhandler() + response = conn_handler.execute_tapget(sub_context, verbose=verbose) + if response.status == 200: + if isinstance(response, Iterable): + for line in response: + + try: + print(line.decode("utf-8").split('=', 1)[1]) + except ValueError as e: + print(e) + except IndexError: + print("Archive down for maintenance") + @staticmethod def __set_dirs(output_file, observation_id): @@ -1601,4 +1598,4 @@ def get_scientific_product_list(self, *, observation_id=None, tile_index=None, c return job.get_results() -Euclid = EuclidClass() +Euclid = EuclidClass(show_server_messages=False) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 70d0e6bad8..92c2612743 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -922,15 +922,13 @@ def get_status_messages(self): the status of eHST TAP """ - try: - esautils.execute_servlet_request( - url=conf.EHST_TAP_SERVER + "/" + conf.EHST_MESSAGES, - tap=self.tap, - query_params={}, - parser_method=self.parse_messages_response - ) - except OSError: - print("Status messages could not be retrieved") + subContext = conf.EHST_MESSAGES + connHandler = self._tap._TapPlus__getconnhandler() + response = connHandler.execute_tapget(subContext, verbose=False) + if response.status == 200: + for line in response: + string_message = line.decode("utf-8") + print(string_message[string_message.index('=') + 1:]) def parse_messages_response(self, response): string_messages = [] @@ -1051,5 +1049,8 @@ def get_datalabs_path(self, filename, default_volume=None): return full_path +<<<<<<< HEAD # Need to be False in order to avoid reaching out to the remote server at import time +======= +>>>>>>> d99705881... remove try/except clauses in more show messages, and set show_messages to false by default at import time ESAHubble = ESAHubbleClass(show_messages=False) diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index b9347e5f4d..c1b29ae053 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -694,16 +694,13 @@ def get_status_messages(self): the status of JWST TAP """ - try: - subContext = conf.JWST_MESSAGES - connHandler = self.__jwsttap._TapPlus__getconnhandler() - response = connHandler.execute_tapget(subContext, verbose=False) - if response.status == 200: - for line in response: - string_message = line.decode("utf-8") - print(string_message[string_message.index('=') + 1:]) - except OSError: - print("Status messages could not be retrieved") + subContext = conf.JWST_MESSAGES + connHandler = self.__jwsttap._TapPlus__getconnhandler() + response = connHandler.execute_tapget(subContext, verbose=False) + if response.status == 200: + for line in response: + string_message = line.decode("utf-8") + print(string_message[string_message.index('=') + 1:]) def get_product_list(self, *, observation_id=None, cal_level="ALL", @@ -1275,4 +1272,4 @@ def get_decoded_string(str): return str -Jwst = JwstClass() +Jwst = JwstClass(show_messages=False) From 44cc79eadb6371da25b67fa81f91c122366249a1 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 11 Jun 2025 15:21:39 -0400 Subject: [PATCH 03/10] ESA hubble tests: no showing messages during non-remote tests --- astroquery/esa/euclid/tests/test_euclidtap.py | 14 +++++++------- .../esa/hubble/tests/test_esa_hubble_remote.py | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/astroquery/esa/euclid/tests/test_euclidtap.py b/astroquery/esa/euclid/tests/test_euclidtap.py index ff2293096d..502b636f2e 100644 --- a/astroquery/esa/euclid/tests/test_euclidtap.py +++ b/astroquery/esa/euclid/tests/test_euclidtap.py @@ -160,25 +160,25 @@ def column_attrs(): def test_load_environments(): - tap = EuclidClass(environment='PDR') + tap = EuclidClass(environment='PDR', show_server_messages=False) assert tap is not None - tap = EuclidClass(environment='IDR') + tap = EuclidClass(environment='IDR', show_server_messages=False) assert tap is not None - tap = EuclidClass(environment='OTF') + tap = EuclidClass(environment='OTF', show_server_messages=False) assert tap is not None - tap = EuclidClass(environment='REG') + tap = EuclidClass(environment='REG', show_server_messages=False) assert tap is not None environment = 'WRONG' try: - tap = EuclidClass(environment='WRONG') + tap = EuclidClass(environment='WRONG', show_server_messages=False) except Exception as e: assert str(e).startswith(f"Invalid environment {environment}. Valid values: {list(conf.ENVIRONMENTS.keys())}") @@ -672,7 +672,7 @@ def test_get_product_list_by_tile_index(): def test_get_product_list_errors(): - tap = EuclidClass() + tap = EuclidClass(show_server_messages=False) with pytest.raises(ValueError, match="Missing required argument: 'product_type'"): tap.get_product_list(observation_id='13', product_type=None) @@ -1140,7 +1140,7 @@ def test_get_scientific_data_product_list(): def test_get_scientific_data_product_list_exceptions(): - eculid = EuclidClass() + eculid = EuclidClass(show_server_messages=False) with pytest.raises(ValueError, match="Include a valid parameter to retrieve a LE3 product."): eculid.get_scientific_product_list(observation_id=None, tile_index=None, category=None, group=None, diff --git a/astroquery/esa/hubble/tests/test_esa_hubble_remote.py b/astroquery/esa/hubble/tests/test_esa_hubble_remote.py index 64f4131fa6..54c8d8e7b6 100644 --- a/astroquery/esa/hubble/tests/test_esa_hubble_remote.py +++ b/astroquery/esa/hubble/tests/test_esa_hubble_remote.py @@ -18,6 +18,7 @@ from astroquery.esa.hubble import ESAHubble from astropy import coordinates +# don't show messages during test: it creates a remote call esa_hubble = ESAHubble(show_messages=False) From 36f426cf33537eb75b64c3a35e4de80ecfe0911c Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Thu, 12 Jun 2025 13:42:57 -0400 Subject: [PATCH 04/10] change to show_messages=True by default, but off at import time correct bad merge --- astroquery/esa/hubble/core.py | 3 --- astroquery/gaia/core.py | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 92c2612743..547976ea43 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1049,8 +1049,5 @@ def get_datalabs_path(self, filename, default_volume=None): return full_path -<<<<<<< HEAD # Need to be False in order to avoid reaching out to the remote server at import time -======= ->>>>>>> d99705881... remove try/except clauses in more show messages, and set show_messages to false by default at import time ESAHubble = ESAHubbleClass(show_messages=False) diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 7c353c9691..65e7c2fae9 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -55,7 +55,7 @@ def __init__(self, *, tap_plus_conn_handler=None, gaia_data_server='https://gea.esac.esa.int/', tap_server_context="tap-server", data_server_context="data-server", - verbose=False, show_server_messages=False): + verbose=False, show_server_messages=True): super(GaiaClass, self).__init__(url=gaia_tap_server, server_context=tap_server_context, tap_context="tap", @@ -1183,4 +1183,4 @@ def get_status_messages(self): print("Archive down for maintenance") -Gaia = GaiaClass() +Gaia = GaiaClass(show_server_messages=False) From 4463d711fe99a6b93e00076c2a901016f4aead07 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 11:24:41 -0500 Subject: [PATCH 05/10] self._tap should be self.tap --- astroquery/esa/hubble/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 547976ea43..7a92545a78 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -923,7 +923,7 @@ def get_status_messages(self): """ subContext = conf.EHST_MESSAGES - connHandler = self._tap._TapPlus__getconnhandler() + connHandler = self.tap._TapPlus__getconnhandler() response = connHandler.execute_tapget(subContext, verbose=False) if response.status == 200: for line in response: From 834555f262d0eb6c79b1d443197ea88eacaf75a9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 11:26:56 -0500 Subject: [PATCH 06/10] fix a bad choice of merge --- astroquery/esa/hubble/core.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 7a92545a78..d89fecf010 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -922,13 +922,12 @@ def get_status_messages(self): the status of eHST TAP """ - subContext = conf.EHST_MESSAGES - connHandler = self.tap._TapPlus__getconnhandler() - response = connHandler.execute_tapget(subContext, verbose=False) - if response.status == 200: - for line in response: - string_message = line.decode("utf-8") - print(string_message[string_message.index('=') + 1:]) + esautils.execute_servlet_request( + url=conf.EHST_TAP_SERVER + "/" + conf.EHST_MESSAGES, + tap=self.tap, + query_params={}, + parser_method=self.parse_messages_response + ) def parse_messages_response(self, response): string_messages = [] From c3de316b9c7f21b7b2274fc3d2c6695111a915b2 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 11:40:34 -0500 Subject: [PATCH 07/10] style checks --- astroquery/esa/euclid/core.py | 1 - astroquery/tests/test_imports.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index 4068f3efb8..8c751f85de 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -768,7 +768,6 @@ def get_status_messages(self, verbose=False): except IndexError: print("Archive down for maintenance") - @staticmethod def __set_dirs(output_file, observation_id): if output_file is None: diff --git a/astroquery/tests/test_imports.py b/astroquery/tests/test_imports.py index 85c0f921e0..b63894cf10 100644 --- a/astroquery/tests/test_imports.py +++ b/astroquery/tests/test_imports.py @@ -2,10 +2,8 @@ import sys import importlib import pytest -import socket from unittest.mock import patch from pytest_remotedata.disable_internet import no_internet -from pytest_remotedata.disable_internet import INTERNET_OFF # List of all astroquery modules to test ASTROQUERY_MODULES = [ @@ -62,6 +60,7 @@ 'astroquery.xmatch', ] + class SocketTracker: def __init__(self): self.socket_attempts = [] @@ -96,6 +95,7 @@ def test_no_http_calls_during_import(module_name): assert not tracker.socket_attempts, ( f"Module {module_name} attempted to create {len(tracker.socket_attempts)} " - f"socket(s) during import:\n" + - "\n".join(f" - {args} {kwargs}" for args, kwargs in tracker.socket_attempts) - ) \ No newline at end of file + "socket(s) during import:\n" + ( + "\n".join(f" - {args} {kwargs}" for args, kwargs in tracker.socket_attempts) + ) + ) From 7c02364b2fa4fe8e02ed9f4bd76721f4e704b899 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 18:56:22 -0500 Subject: [PATCH 08/10] add several explicit tests of get_status_message (and raise exceptions if query fails) --- astroquery/esa/euclid/core.py | 1 + astroquery/esa/euclid/tests/test_euclid_remote.py | 7 +++++++ astroquery/esa/hubble/tests/test_esa_hubble_remote.py | 7 +++++++ astroquery/esa/jwst/core.py | 1 + astroquery/esa/jwst/tests/test_jwstdata.py | 7 +++++++ astroquery/gaia/core.py | 1 + astroquery/gaia/tests/test_gaia_remote.py | 7 +++++++ 7 files changed, 31 insertions(+) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index 8c751f85de..ff878e3bc1 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -757,6 +757,7 @@ def get_status_messages(self, verbose=False): sub_context = self.EUCLID_MESSAGES conn_handler = self._TapPlus__getconnhandler() response = conn_handler.execute_tapget(sub_context, verbose=verbose) + response.raise_for_status() if response.status == 200: if isinstance(response, Iterable): for line in response: diff --git a/astroquery/esa/euclid/tests/test_euclid_remote.py b/astroquery/esa/euclid/tests/test_euclid_remote.py index 6d5f3e61f9..c82bf075f9 100644 --- a/astroquery/esa/euclid/tests/test_euclid_remote.py +++ b/astroquery/esa/euclid/tests/test_euclid_remote.py @@ -76,3 +76,10 @@ def test_get_tables(): table = euclid.load_table("catalogue.mer_catalogue") assert len(table.columns) == 471 + + +@pytest.mark.remote_data +def test_get_status_messages(): + euclid = EuclidClass(show_server_messages=True) + # redundant, but added to be extra-explicit + euclid.get_status_messages() diff --git a/astroquery/esa/hubble/tests/test_esa_hubble_remote.py b/astroquery/esa/hubble/tests/test_esa_hubble_remote.py index 54c8d8e7b6..570d6b8cb4 100644 --- a/astroquery/esa/hubble/tests/test_esa_hubble_remote.py +++ b/astroquery/esa/hubble/tests/test_esa_hubble_remote.py @@ -144,3 +144,10 @@ def test_get_datalabs_path_fits(self, recwarn): assert len(recwarn) == 1 assert "ib4x04ivq_flt.fits" in str(recwarn[0].message) assert result == '/data/hub_hstdata_i/i/b4x/04/ib4x04ivq_flt.fits.gz' + + +@pytest.mark.remote_data +def test_get_status_messages(): + esa_hubble = ESAHubble(show_messages=True) + # redundant, but added to be extra-explicit + esa_hubble.get_status_messages() diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index c1b29ae053..daffb1a162 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -697,6 +697,7 @@ def get_status_messages(self): subContext = conf.JWST_MESSAGES connHandler = self.__jwsttap._TapPlus__getconnhandler() response = connHandler.execute_tapget(subContext, verbose=False) + response.raise_for_status() if response.status == 200: for line in response: string_message = line.decode("utf-8") diff --git a/astroquery/esa/jwst/tests/test_jwstdata.py b/astroquery/esa/jwst/tests/test_jwstdata.py index 834b80e786..f76717264d 100644 --- a/astroquery/esa/jwst/tests/test_jwstdata.py +++ b/astroquery/esa/jwst/tests/test_jwstdata.py @@ -66,3 +66,10 @@ def test_login_error(): with pytest.raises(HTTPError) as err: jwst.login(user="dummy", password="dummy") assert "Unauthorized" in err.value.args[0] + + +@pytest.mark.remote_data +def test_get_status_messages(): + jwst = JwstClass(show_messages=True) + # redundant, but added to be extra-explicit + jwst.get_status_messages() diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 65e7c2fae9..4882fdb93f 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -1171,6 +1171,7 @@ def get_status_messages(self): sub_context = self.GAIA_MESSAGES conn_handler = self._TapPlus__getconnhandler() response = conn_handler.execute_tapget(sub_context, verbose=False) + response.raise_for_status() if response.status == 200: if isinstance(response, Iterable): for line in response: diff --git a/astroquery/gaia/tests/test_gaia_remote.py b/astroquery/gaia/tests/test_gaia_remote.py index 2fd6e4b8e2..86efae0ddd 100644 --- a/astroquery/gaia/tests/test_gaia_remote.py +++ b/astroquery/gaia/tests/test_gaia_remote.py @@ -67,3 +67,10 @@ def test_search_async_jobs(): jobfilter.limit = 10 jobs = gaia.search_async_jobs(jobfilter=jobfilter, verbose=True) assert len(jobs) == 10 + + +@pytest.mark.remote_data +def test_get_status_messages(): + gaia = GaiaClass(show_server_messages=True) + # redundant, but added to be extra-explicit + gaia.get_status_messages() From 05331b326d8277f3710b1457484225ab9ea0b7d1 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 19:06:07 -0500 Subject: [PATCH 09/10] fix tests to raise non-200 status code messages --- astroquery/esa/euclid/core.py | 3 ++- astroquery/esa/jwst/core.py | 3 ++- astroquery/gaia/core.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index ff878e3bc1..6fa501abd8 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -757,7 +757,6 @@ def get_status_messages(self, verbose=False): sub_context = self.EUCLID_MESSAGES conn_handler = self._TapPlus__getconnhandler() response = conn_handler.execute_tapget(sub_context, verbose=verbose) - response.raise_for_status() if response.status == 200: if isinstance(response, Iterable): for line in response: @@ -768,6 +767,8 @@ def get_status_messages(self, verbose=False): print(e) except IndexError: print("Archive down for maintenance") + else: + raise HTTPError(f"Failed to retrieve status messages. HTTP status code: {response.status}") @staticmethod def __set_dirs(output_file, observation_id): diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index daffb1a162..69bd0cb00f 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -697,11 +697,12 @@ def get_status_messages(self): subContext = conf.JWST_MESSAGES connHandler = self.__jwsttap._TapPlus__getconnhandler() response = connHandler.execute_tapget(subContext, verbose=False) - response.raise_for_status() if response.status == 200: for line in response: string_message = line.decode("utf-8") print(string_message[string_message.index('=') + 1:]) + else: + raise HTTPError(f"Failed to retrieve status messages. HTTP status code: {response.status}") def get_product_list(self, *, observation_id=None, cal_level="ALL", diff --git a/astroquery/gaia/core.py b/astroquery/gaia/core.py index 4882fdb93f..6adcd68ca6 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -1171,7 +1171,6 @@ def get_status_messages(self): sub_context = self.GAIA_MESSAGES conn_handler = self._TapPlus__getconnhandler() response = conn_handler.execute_tapget(sub_context, verbose=False) - response.raise_for_status() if response.status == 200: if isinstance(response, Iterable): for line in response: @@ -1182,6 +1181,8 @@ def get_status_messages(self): print(e) except IndexError: print("Archive down for maintenance") + else: + raise HTTPError(f"Failed to retrieve status messages. HTTP status code: {response.status}") Gaia = GaiaClass(show_server_messages=False) From e6bb57c3ad3ac8f944230efa727eb75cad54a73e Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 21:53:02 -0500 Subject: [PATCH 10/10] import --- astroquery/esa/jwst/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/astroquery/esa/jwst/core.py b/astroquery/esa/jwst/core.py index 69bd0cb00f..3fa2314f58 100644 --- a/astroquery/esa/jwst/core.py +++ b/astroquery/esa/jwst/core.py @@ -17,6 +17,7 @@ import zipfile from datetime import datetime, timezone from urllib.parse import urlencode +from requests.exceptions import HTTPError import astroquery.esa.utils.utils as esautils