0

So I am making an project that call user API from github and after 60 times I will get this error:

enter image description here

And I want if user got that error I want it return a page like this: enter image description here

How can I do that ?

nathannewyen
  • 233
  • 6
  • 22
  • HTTP rate limits are there to stop users from abusing a service. You will have to throttle your requests, so that you don't hit this limit – borisdonchev Jul 04 '20 at 08:43
  • Another possibility would be to use proxies to call this API. This way the limit will be multiplied by the number of IPs that you have – borisdonchev Jul 04 '20 at 08:44
  • but if I hit the limit can i return render a page like for this error ? – nathannewyen Jul 04 '20 at 08:49
  • all you need: https://stackoverflow.com/questions/6618939/how-do-i-raise-a-response-forbidden-in-django – JSRB Jul 04 '20 at 08:52
  • These two is what you need https://docs.djangoproject.com/en/3.0/ref/views/ https://docs.djangoproject.com/en/3.0/topics/http/views/#customizing-error-views – Ahmet Jul 04 '20 at 09:00

1 Answers1

-2
You could accomplish this by using Try/except handling,since it's the best way to handle request errors(in general) sush as (Timeout/to many requests, etc ..) :
 
try:
    r = requests.get(url, params={'s': thing})
except requests.exceptions.Timeout:
    # Maybe set up for a retry, or continue in a retry loop
except requests.exceptions.TooManyRedirects:
    # Tell the user their URL was bad and try a different one
    # You can add more except statements here as well. (for the page you can render it , to be shown in place of that django default error)

give this doc a shot might find it helpful : https://requests.readthedocs.io/en/latest/user/quickstart/#errors-and-exceptions

Archiee
  • 85
  • 9