diff --git a/brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py b/brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py index 57340dae..ec9e5654 100644 --- a/brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py +++ b/brainrender/atlas_specific/allen_brain_atlas/gene_expression/api.py @@ -2,6 +2,7 @@ import sys import pandas as pd +import requests from loguru import logger from brainrender import base_dir @@ -86,7 +87,16 @@ def get_gene_experiments(self, gene): :param gene_symbol: str """ url = self.gene_experiments_url.replace("-GENE_SYMBOL-", gene) - data = request(url).json()["msg"] + max_retries = 5 + delay = 4 + + for i in range(max_retries): + try: + data = request(url).json()["msg"] + break + except requests.exceptions.JSONDecodeError: + print(f"Unable to connect to Allen API, retrying in {delay}") + delay *= 2 if not len(data): print(f"No experiment found for gene {gene}")