code: def request_with_retry(func, *args, **kwargs):
      
      max_retries = kwargs.pop('max_retries', 30)
      sleep = 2
      retry_count = 0
      while True:
          try:
              response = func(*args, **kwargs)
              response.raise_for_status()
              return response
          except (requests.exceptions.ConnectionError,
                  requests.exceptions.HTTPError,  # XXX 500s aren't retryable
                  requests.exceptions.Timeout) as e:
              if retry_count == max_retries:
                  return e
              retry_count += 1
              delay = sleep + random.random() * 0.25 * sleep
              if isinstance(e, requests.exceptions.HTTPError) and e.response.status_code == 429:
                  logger.info(
                      "Rate limit exceeded, retrying in %s seconds" % delay)
              else:
                  logger.warning('requests_with_retry encountered retryable exception: %s. args: %s, kwargs: %s',
                                 e, args, kwargs)
              time.sleep(delay)
              sleep *= 2
              if sleep > MAX_SLEEP_SECONDS:
                  sleep = MAX_SLEEP_SECONDS
          except requests.exceptions.RequestException as e:
              logger.error(response.json()['error'])  # XXX clean this up
              logger.exception(
                  'requests_with_retry encountered unretryable exception: %s', e)
              return e
docs: Perform a requests http call, retrying with exponential backoff.
  
      Args:
          func: An http-requesting function to call, like requests.post
          max_retries: Maximum retries before giving up. By default we retry 30 times in ~2 hours before dropping the chunk
          *args: passed through to func
          **kwargs: passed through to func