question 306 HTTP & API Clients · medium
The count that is always zero
event_count(opener, url) asks the USGS count endpoint how many events match. After someone added a line that logs the size of the response, the function returns 0 for every query, and nobody noticed because it never raises. Fix it so it returns the real count, and so a body that isn't JSON raises an error instead of quietly becoming 0.
Simulated: this runs against results recorded on real Python.
Function
event_count(opener, url)Returnsthe
count from the JSON bodyRaises
json.JSONDecodeError when the body isn't JSON (for example an HTML error page sent with status 200)