Plow Technologies has implemented throttling on some OnPing API routes, with more to be added in the future. This is necessary to protect our systems from overload caused by automated requests and to preserve availability and quality of service for all of our customers.
When a user makes more requests than our throttling policy permits, OnPing will return the HTTP status code 429 Too Many Requests.
This status code indicates that the user has made more requests than the throttling policy allows. The response will include a header specifying how many seconds to wait before making another request. Note that waiting this long does not guarantee that a request will be successful. It is only the server’s estimate of how long you must wait before another request will be allowed.
It is not difficult to write scripts that gracefully handle throttling. The “Too many requests” status code should not be treated as an error but as a signal to slow the rate of requests. Automated processes that receive this response should wait at least the specified amount of time and then retry the request.
Python
In Python, we can investigate the status of a response returned to a request made with the requests library:
import requests
import time
while(true):
r = requests.get('https://onping.plowtech.net/path/to/api', json = myJson, cookies = myCookies)
if r.status_code == requests.codes.too_many_requests:
time.sleep(int(r.headers['retry-after'])+5)
continue
else:
break
print r.text
By placing the request inside the loop, we can easily conditionally retry it. Before retrying, we look up the retry-after header in the response and sleep for that many seconds.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article