runtime
306 / 500
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.

Functionevent_count(opener, url)
Returnsthe count from the JSON body
Raisesjson.JSONDecodeError when the body isn't JSON (for example an HTML error page sent with status 200)

Loading your progress…

The count that is always zero — Python practice · Runtime