It would be good to either check for specific status codes / messages from the upstream API[1] or even just use the raise_for_status[2] method from requests. At the moment I have to inspect exception.message in order to figure out what the actual issue was when connecting to the API. I think it would be preferable to write, e.g.:
try:
result = run_query()
except RateLimitException:
time.sleep(5)
result = run_query()
versus what I have now:
try:
result = run_query()
except Exception as ex:
if ex.message = 'rate limit exceeded':
time.sleep(5)
result = run_query()
else:
raise
It might also be useful if the "quota exceeded" error response returned 402 rather than 429, but that's a general issue, not specific to the Python library. Thanks!
It would be good to either check for specific status codes / messages from the upstream API[1] or even just use the
raise_for_status
[2] method fromrequests
. At the moment I have to inspectexception.message
in order to figure out what the actual issue was when connecting to the API. I think it would be preferable to write, e.g.:versus what I have now:
It might also be useful if the "quota exceeded" error response returned 402 rather than 429, but that's a general issue, not specific to the Python library. Thanks!
[1] https://docs.webhose.io/docs/things-every-developer-should-know#section-http-status-codes [2] http://docs.python-requests.org/en/master/user/quickstart/#response-status-codes