From 21b6a7fe5eae3ae5521028c8abb08518a81f8043 Mon Sep 17 00:00:00 2001 From: Matthieu Barba Date: Fri, 15 Mar 2024 17:49:33 +0000 Subject: [PATCH] Fix new URL + better check --- src/python/ensembl/io/genomio/seq_region/prepare.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/python/ensembl/io/genomio/seq_region/prepare.py b/src/python/ensembl/io/genomio/seq_region/prepare.py index 3bf91e572..0e5a61feb 100644 --- a/src/python/ensembl/io/genomio/seq_region/prepare.py +++ b/src/python/ensembl/io/genomio/seq_region/prepare.py @@ -160,9 +160,14 @@ def add_mitochondrial_codon_table(seq_regions: List[SeqRegion], taxon_id: int) - taxon_id: The species taxon ID. """ - url = f"https://www.ebi.ac.uk/ena/data/taxonomy/v1/taxon/tax-id/{str(taxon_id)}" + url = f"https://www.ebi.ac.uk/ena/taxonomy/rest/tax-id/{str(taxon_id)}" response = requests.get(url, headers={"Content-Type": "application/json"}, timeout=60) + response.raise_for_status() + # In case we've been redirected, check for html opening tag + if response.text.startswith("<"): + raise ValueError(f"Response from {url} is not JSON") decoded = response.json() + if "mitochondrialGeneticCode" not in decoded: logging.warning("No mitochondria genetic code found for taxon {taxon_id}") else: