You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defmake_throttle_hook(timeout=2):
"""Returns a response hook function which sleeps for <timeout> seconds if the response status_code/content meet certain criteria before re-requesting the content. The timeout length grows for each re-request until it exceeds a threshold, at which point simply return the response object. """importtimedefmyhook(resp):
iftimeout<1025:
if (resp.status_code==403) and ("too_many"inresp.content):
time.sleep(timeout)
proxies=resp.request.proxiescookies=resp.request.cookiesauth=resp.request.authhooks= {'response': make_throttle_hook(timeout=timeout*3)}
returnrequests.get(resp.url, proxies=proxies, cookies=cookies, auth=auth, hooks=hooks)
returnrespreturnmyhookresp=requests.get(url, hooks={'response': make_throttle_hook(5)})