You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using a search radius > 180 km causes a http 400 error, but libcomcat does not check http error code before trying to parse json.
To Reproduce
Steps to reproduce the behavior:
from libcomcat.search import search
from datetime import datetime
start = datetime.fromisoformat('2020-11-20T03:19:00')
end = datetime.fromisoformat('2020-11-20T03:20:00')
# eq search paramaters
radius = 500 # km
lat = -53.9
lon = 140.5
minmag = 5
summary_events = search(starttime=start,
endtime = end,
maxradius=radius,
latitude=-lat,
longitude=lon,
minmagnitude=minmag)
Expected behavior
Check http error code, do not parse as json if not success, return http error message to user.
Screenshots
python3 testcomcat.py
Traceback (most recent call last):
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/site-packages/libcomcat/search.py", line 536, in _search
jdict = response.json()
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testcomcat.py", line 18, in <module>
minmagnitude=minmag)
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/site-packages/libcomcat/search.py", line 468, in search
events += _search(**newargs)
File "/Users/crotwell/opt/miniconda3/envs/obspy/lib/python3.7/site-packages/libcomcat/search.py", line 554, in _search
raise ConnectionError(fmt % (url, msg))
ConnectionError: Error downloading data from url https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2020-11-20T03%3A19%3A00&endtime=2020-11-20T03%3A20%3A00&latitude=53.9&longitude=140.5&maxradius=500&limit=20000&maxdepth=1000&maxmagnitude=10.0&mindepth=-100&minmagnitude=5&offset=1&orderby=time-asc&eventtype=earthquake. "Expecting value: line 1 column 1 (char 0)".
Environmnet (please complete the following information):
Additional context
Add any other context about the problem here.
On about line 546 in libcomcat/search.py, the HTTPError is caught, but only 503 is actually handled. Any other error code is silently eaten. In general, if you do not handle an error you should re-raise.
The text was updated successfully, but these errors were encountered:
Describe the bug
Using a search radius > 180 km causes a http 400 error, but libcomcat does not check http error code before trying to parse json.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Check http error code, do not parse as json if not success, return http error message to user.
Screenshots
Environmnet (please complete the following information):
Additional context
Add any other context about the problem here.
On about line 546 in libcomcat/search.py, the HTTPError is caught, but only 503 is actually handled. Any other error code is silently eaten. In general, if you do not handle an error you should re-raise.
The text was updated successfully, but these errors were encountered: