JSON Decode error while service was unavailable
Bit of an edge case and realise this is probably only temporary package but while the SOAR was down for maintenance got a json decode error -
result = Fido.search(Time('2021-01-01', '2021-01-15') & Instrument('EUI'))
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-8-1b961ccfb6a9> in <module>
----> 1 result = Fido.search(Time('2021-01-01', '2021-01-15') & Instrument('EUI'))
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy/net/fido_factory.py in search(self, *query)
346 """
347 query = attr.and_(*query)
--> 348 results = query_walker.create(query, self)
349
350 # If we have searched the VSO but no results were returned, but another
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy/net/attr.py in create(self, *args, **kwargs)
563 Call the create function(s) matching the arguments to this method.
564 """
--> 565 return self.createmm(self, *args, **kwargs)
566
567 def apply(self, *args, **kwargs):
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy/util/functools.py in wrapper(*args, **kwargs)
16
17 def wrapper(*args, **kwargs):
---> 18 return dispatcher.dispatch(args[1].__class__)(*args, **kwargs)
19
20 wrapper.dispatch = dispatcher.dispatch
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy/net/fido_factory.py in _create_and(walker, query, factory)
275 @query_walker.add_creator(attr.AttrAnd)
276 def _create_and(walker, query, factory):
--> 277 return factory._make_query_to_client(*query.attrs)
278
279
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy/net/fido_factory.py in _make_query_to_client(self, *query)
511 if isinstance(tmpclient, vso.VSOClient):
512 kwargs = dict(response_format="table")
--> 513 results.append(tmpclient.search(*query, **kwargs))
514
515 # This method is called by `search` and the results are fed into a
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy_soar/client.py in search(self, *query, **kwargs)
25 results = []
26 for query_parameters in queries:
---> 27 results.append(self._do_search(query_parameters))
28 table = astropy.table.vstack(results)
29 qrt = QueryResponseTable(table, client=self)
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/sunpy_soar/client.py in _do_search(query)
63
64 # Do some list/dict wrangling
---> 65 names = [m['name'] for m in r.json()['metadata']]
66 info = {name: [] for name in names}
67 for entry in r.json()['data']:
~/.virtualenvs/radiospectra/lib/python3.7/site-packages/requests/models.py in json(self, **kwargs)
898 # used.
899 pass
--> 900 return complexjson.loads(self.text, **kwargs)
901
902 @property
~/.pyenv/versions/3.7.0/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~/.pyenv/versions/3.7.0/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~/.pyenv/versions/3.7.0/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Would you expect the client to raise a better error, or return zero results and not error?
Hum I guess raise an error, but maybe that's not very user friendly? I assume it go a 200 response but there was just no json in it hence the json decode. It's probably going to be rare occurrence so maybe it doesn't need to be "fixed"?
👍 - definitely worth fixing I think. Having thought about this a bit more, it should probably just return zero results so other clients have a chance to return results too. I've opened https://github.com/sunpy/sunpy/issues/5661 though, to try and get sunpy to have a way of communicating to the user that there's zero results because a server is down.