Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http error code not handled #236

Open
crotwell opened this issue Nov 20, 2020 · 0 comments
Open

http error code not handled #236

crotwell opened this issue Nov 20, 2020 · 0 comments
Labels

Comments

@crotwell
Copy link

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):

  • OS: [e.g. macOS]
  • Python Version [e.g. 3.6] 3.7
  • Libcomcat Version [e.g. 1.0] 2.0.6
  • Numpy Version [e.g. 1.17]
{'date': '2020-09-03T08:41:34-0600', 'dirty': False, 'error': None, 'full-revisionid': '5d3fcb2b7c15f9786016942c0f88dc3595c3416a', 'version': '2.0.6'}

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.

@crotwell crotwell added the bug label Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant