def OpenServerEndpoint(self, path, verify_cb=lambda x: True, data=None,
                         request_opts=None):
    """Search through all the base URLs to connect to one that works."""
    tries = 0
    last_error = HTTPObject(code=404)

    while tries < len(self.base_urls):
      base_url_index = self.last_base_url_index % len(self.base_urls)
      active_base_url = self.base_urls[base_url_index]

      result = self.OpenURL(self._ConcatenateURL(active_base_url, path),
                            data=data, verify_cb=verify_cb,
                            request_opts=request_opts)

      if not result.Success():
        tries += 1
        self.last_base_url_index += 1
        last_error = result
        continue

      # The URL worked - we record that.
      self.active_base_url = active_base_url

      return result

    # No connection is possible at all.
    logging.info("Could not connect to GRR servers %s, directly or through "
                 "these proxies: %s.", self.base_urls, self.proxies)

    return last_error
dataset/ETHPy150Open google/grr/grr/client/comms.py/HTTPManager.OpenServerEndpoint/original