Commit a181ee2f authored by Bruno Duyé's avatar Bruno Duyé

Download: detect exeeded requests quota and wait before trying again

parent 6395109e
......@@ -35,6 +35,7 @@ Options:
import logging
import os
import sys
import time
from docopt import docopt
from requests import Session, exceptions
......@@ -132,8 +133,21 @@ def get_from_api(url, raise_on_errors=True):
global debug_mode
assert url
response = requests_session.get(url)
content_str = response.content
# Try to get answer, retrying if quota exceeded
sleeps_times = [1,1,2,3,5,8]
sleep_time_index = 0 # sleep time index in sleeps_times array
while True:
response = requests_session.get(url)
content_str = response.content
if content_str.startswith(b"<BEAAPI>") and b"Exceeded request quota per minute" in content_str:
waiting_time = sleeps_times[sleep_time_index]"Exceeded request quota per minute. Waiting {} seconds ...".format(waiting_time))
if sleep_time_index < len(sleeps_times) - 1:
sleep_time_index += 1
# Convert json answer and return result
content_dict = json.loads(content_str)
except Exception as e:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment