HTTP Error 503 or 504 when using Ontologies API

Hi all,

I’m using the AllenSDK (2.16.2 on python 3.11, Windows 11) to download a StructureTree. When I run the following code I get an HTTP error:

from allensdk.api.queries.ontologies_api import OntologiesApi
oapi = OntologiesApi()
structure_graph = oapi.get_structures_with_sets([1])

The error is HTTPError: HTTP Error 503: Service Unavailable. Sometimes when running the same code, I will instead get HTTP Error 504: Gateway Time-out.

I get the same behavior running on an AllenSDK installation on my Ubuntu 18.04 workstation

I suspect this is a server error?

I should note that I have no issue accessing the MouseConnectivityApi to download annotation volumes, so it seems to be just an OntologiesAPI service issue and not all AllenAPI services.

Full error stack follows

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In[11], line 2
      1 oapi = OntologiesApi()
----> 2 structure_graph = oapi.get_structures_with_sets([1])  # 1 is the id of the adult mouse structure graph
      3 structure_graph = StructureTree.clean_structures(structure_graph)
      4 tree = StructureTree(structure_graph)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\warehouse_cache\cache.py:661, in cacheable.<locals>.decor.<locals>.w(*args, **kwargs)
    658 if decor.post and not 'post in kwargs':
    659     kwargs['post'] = decor.post
--> 661 result = Cache.cacher(func,
    662                       *args,
    663                       **kwargs)
    664 return result

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\warehouse_cache\cache.py:378, in Cache.cacher(fn, *args, **kwargs)
    375         strategy = 'create'
    377 if strategy == 'pass_through':
--> 378     data = fn(*args, **kwargs)
    379 elif strategy in ['create']:
    380     Manifest.safe_make_parent_dirs(path)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\queries\ontologies_api.py:235, in OntologiesApi.get_structures_with_sets(self, structure_graph_ids, order, num_rows, count, **kwargs)
    214 @cacheable()
    215 def get_structures_with_sets(self, structure_graph_ids, order=['structures.graph_order'], 
    216                              num_rows='all', count=False, **kwargs):
    217     '''Download structures along with the sets to which they belong.
    218 
    219     Parameters
   (...)
    232 
    233     '''
--> 235     return self.template_query('ontology_queries', 'structures_with_sets', 
    236                                graph_ids=structure_graph_ids, 
    237                                order=order, num_rows=num_rows, 
    238                                count=count)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\queries\rma_template.py:132, in RmaTemplate.template_query(self, template_name, entry_name, **kwargs)
    128     query_args['order'] = template['order']
    130 query_args.update(kwargs)
--> 132 data = self.model_query(**query_args)
    134 return data

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\queries\rma_api.py:257, in RmaApi.model_query(self, *args, **kwargs)
    217 def model_query(self, *args, **kwargs):
    218     '''Construct and execute a model stage of an RMA query string.
    219 
    220     Parameters
   (...)
    255     response, including the normalized query.
    256     '''
--> 257     return self.json_msg_query(
    258         self.build_query_url(
    259             self.model_stage(*args, **kwargs)))

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\api.py:164, in Api.json_msg_query(self, url, dataframe)
    147 def json_msg_query(self, url, dataframe=False):
    148     ''' Common case where the url is fully constructed
    149         and the response data is stored in the 'msg' field.
    150 
   (...)
    161         returned data; type depends on dataframe option
    162     '''
--> 164     data = self.do_query(lambda *a, **k: url,
    165                          self.read_data)
    167     if dataframe is True:
    168         warnings.warn("dataframe argument is deprecated", DeprecationWarning)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\api.py:204, in Api.do_query(self, url_builder_fn, json_traversal_fn, *args, **kwargs)
    200 api_url = url_builder_fn(*args, **kwargs)
    202 post = kwargs.get('post', False)
--> 204 json_parsed_data = self.retrieve_parsed_json_over_http(api_url, post)
    206 return json_traversal_fn(json_parsed_data)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\api\api.py:369, in Api.retrieve_parsed_json_over_http(self, url, post)
    366 self._log.info("Downloading URL: %s", url)
    368 if post is False:
--> 369     data = json_utilities.read_url_get(
    370         requests.utils.quote(url,
    371                              ';/?:@&=+$,'))
    372 else:
    373     data = json_utilities.read_url_post(url)

File C:\ProgramData\anaconda3\Lib\site-packages\allensdk\core\json_utilities.py:115, in read_url_get(url)
     98 def read_url_get(url):
     99     """Transform a JSON contained in a file into an equivalent
    100     nested python dict.
    101 
   (...)
    113     the output will be of the corresponding type.
    114     """
--> 115     response = urllib_request.urlopen(url)
    116     json_string = response.read().decode("utf-8")
    118     return json.loads(json_string)

File C:\ProgramData\anaconda3\Lib\urllib\request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    214 else:
    215     opener = _opener
--> 216 return opener.open(url, data, timeout)

File C:\ProgramData\anaconda3\Lib\urllib\request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)
    523 for processor in self.process_response.get(protocol, []):
    524     meth = getattr(processor, meth_name)
--> 525     response = meth(req, response)
    527 return response

File C:\ProgramData\anaconda3\Lib\urllib\request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
    631 # According to RFC 2616, "2xx" code indicates that the client's
    632 # request was successfully received, understood, and accepted.
    633 if not (200 <= code < 300):
--> 634     response = self.parent.error(
    635         'http', request, response, code, msg, hdrs)
    637 return response

File C:\ProgramData\anaconda3\Lib\urllib\request.py:563, in OpenerDirector.error(self, proto, *args)
    561 if http_err:
    562     args = (dict, 'default', 'http_error_default') + orig_args
--> 563     return self._call_chain(*args)

File C:\ProgramData\anaconda3\Lib\urllib\request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    494 for handler in handlers:
    495     func = getattr(handler, meth_name)
--> 496     result = func(*args)
    497     if result is not None:
    498         return result

File C:\ProgramData\anaconda3\Lib\urllib\request.py:643, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643     raise HTTPError(req.full_url, code, msg, hdrs, fp)

Thank you for reporting this issue, and for your patience. The server was restarted and the API is now responding.

Please try again at your convenience.

1 Like