import logging
import requests
import time


def request_url_json(url: str, max_retries: int = 1, retry_interval: int = 10) -> dict:
    """Get JSON object version of reponse to GET request to given URL.
        Handles exception ReadTimeout.
  Args:
    url: URL to make the GET request.
    max_retries: Number of timeout retries to be made before returning empty dict.
    retry_interval: Wait interval in seconds before retying.

  Returns:
    JSON decoded response from the GET call.
      Empty dict is returned in case the call times out after max_retries.
  """
    logging.info('Requesting url: %s', url)
    try:
        req = requests.get(url)
        if req.status_code == requests.codes.ok:
            response_data = req.json()
        else:
            response_data = {'http_err_code': req.status_code}
            logging.error('HTTP status code: ' + str(req.status_code))
        return response_data
    except requests.exceptions.ReadTimeout:
        if max_retries> 0:
          logging.warning('Timeout occoured, retrying after 10s.')
          time.sleep(10)
          return request_url_json(url, max_retries - 1, retry_interval)
        else:
          return {}