From c720e0b1662b78f5b334902be077100a047acb4a Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 11 Jun 2025 12:38:54 -0400 Subject: [PATCH 1/8] 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 6cec25311d..0cc2dcb4bc 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -56,7 +56,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", @@ -1202,23 +1202,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 ed89279a63d95d400e15743cdb74d5338aab18fa Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 11 Jun 2025 14:48:56 -0400 Subject: [PATCH 2/8] 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 0d9ef7bb7f..b29da09f8b 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -773,23 +773,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): @@ -1857,4 +1854,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 41481502c2..e3252ef402 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -856,15 +856,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 = [] @@ -1014,5 +1012,8 @@ def __get_default_datalabs_path(self, datalabs_path, path_parsed, filename): return f"{datalabs_path}hub_{path_parsed}/{filename}" +<<<<<<< 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 2a79ae08a0b3ab181b9349c1d7e124cd0df09ace Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 24 Jul 2026 15:42:01 -0400 Subject: [PATCH 3/8] ESA hubble tests: no showing messages during non-remote tests --- astroquery/esa/euclid/tests/test_euclidtap.py | 12 ++++++------ .../esa/hubble/tests/test_esa_hubble_remote.py | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/astroquery/esa/euclid/tests/test_euclidtap.py b/astroquery/esa/euclid/tests/test_euclidtap.py index d6ec4c350b..4099ca8ec6 100644 --- a/astroquery/esa/euclid/tests/test_euclidtap.py +++ b/astroquery/esa/euclid/tests/test_euclidtap.py @@ -173,25 +173,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())}") @@ -776,7 +776,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) diff --git a/astroquery/esa/hubble/tests/test_esa_hubble_remote.py b/astroquery/esa/hubble/tests/test_esa_hubble_remote.py index 4b93052caf..9b3e2f1509 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 73d01cb98f414849de7ebf935f7a48ba89fa16c5 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Thu, 12 Jun 2025 13:42:57 -0400 Subject: [PATCH 4/8] 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 e3252ef402..515acb658f 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -1012,8 +1012,5 @@ def __get_default_datalabs_path(self, datalabs_path, path_parsed, filename): return f"{datalabs_path}hub_{path_parsed}/{filename}" -<<<<<<< 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 0cc2dcb4bc..cff69966d5 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -56,7 +56,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", @@ -1217,4 +1217,4 @@ def get_status_messages(self): print("Archive down for maintenance") -Gaia = GaiaClass() +Gaia = GaiaClass(show_server_messages=False) From ab8cd227ee0f2b5b83e75b4f8cedd9d31f500fbf Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 11:24:41 -0500 Subject: [PATCH 5/8] 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 515acb658f..d95425fd18 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -857,7 +857,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 ae01a7ce93d656cb2c84ed6ac90ed9ace087b48a Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 11:26:56 -0500 Subject: [PATCH 6/8] fix a bad choice of merge style checks --- astroquery/esa/euclid/core.py | 1 - astroquery/esa/hubble/core.py | 13 ++++++------- astroquery/tests/test_imports.py | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index b29da09f8b..23d3e6d02c 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -787,7 +787,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/esa/hubble/core.py b/astroquery/esa/hubble/core.py index d95425fd18..cb8f6cb198 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -856,13 +856,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 = [] 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 3a19700db18f6d2eb4dbeb54c752f39db17e2a22 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 18:56:22 -0500 Subject: [PATCH 7/8] 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 23d3e6d02c..7c337d56bb 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -776,6 +776,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 68826b37de..c4b7dc8e55 100644 --- a/astroquery/esa/euclid/tests/test_euclid_remote.py +++ b/astroquery/esa/euclid/tests/test_euclid_remote.py @@ -77,3 +77,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 9b3e2f1509..8101ea0596 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 cff69966d5..c183041b5e 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -1205,6 +1205,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 f33bbf735dcd517e8eb0d8ea2823a21d44fb7ce0 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 1 Dec 2025 19:06:07 -0500 Subject: [PATCH 8/8] fix tests to raise non-200 status code messages import --- astroquery/esa/euclid/core.py | 3 ++- astroquery/esa/jwst/core.py | 4 +++- astroquery/gaia/core.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/astroquery/esa/euclid/core.py b/astroquery/esa/euclid/core.py index 7c337d56bb..e0c889b556 100644 --- a/astroquery/esa/euclid/core.py +++ b/astroquery/esa/euclid/core.py @@ -776,7 +776,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: @@ -787,6 +786,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..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 @@ -697,11 +698,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 c183041b5e..9beb5ef28c 100644 --- a/astroquery/gaia/core.py +++ b/astroquery/gaia/core.py @@ -1205,7 +1205,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: @@ -1216,6 +1215,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)