code: def get_locations(self, url):
          
          if not is_valid_url(url):
              raise InvalidURLError('{} is not a valid URL'.format(url))
          try:
              response = self.session.head(url)
          except (ConnectionError, InvalidSchema, Timeout):
              raise StopIteration
          try:
              generator = self.session.resolve_redirects(
                  response,
                  response.request
              )
              for response in generator:
                  yield response.url
          except InvalidURL:
              pass
          except (ConnectionError, InvalidSchema, Timeout) as error:
              last_url = response.headers['location']
              if isinstance(error, Timeout) or is_valid_url(last_url):
                  yield last_url
docs: Get valid location header values from responses.
  
          :param url: a URL address. If a HEAD request sent to it
          fails because the address has invalid schema, times out
          or there is a connection error, the generator yields nothing.
          :returns: valid redirection addresses. If a request for
          a redirection address fails, and the address is still a valid
          URL string, it's included as the last yielded value. If it's
          not, the previous value is the last one.
          :raises ValuError: if the argument is not a valid URL