code: def _call_api(self, api_url, err_env):
          
          while True:  # may retry on error
              api_request = urllib2.Request(
                  api_url, headers={"Accept-Encoding": "gzip"})
  
              log.debug("Amazon URL: %s" % api_url)
  
              try:
                  if self.Timeout and sys.version[:3] in ["2.4", "2.5"]:
                      # urllib2.urlopen() doesn't accept timeout until 2.6
                      old_timeout = socket.getdefaulttimeout()
                      try:
                          socket.setdefaulttimeout(self.Timeout)
                          return urllib2.urlopen(api_request)
                      finally:
                          socket.setdefaulttimeout(old_timeout)
                  else:
                      # the simple way
                      return urllib2.urlopen(api_request, timeout=self.Timeout)
              except:
                  if not self.ErrorHandler:
                      raise
  
                  exception = sys.exc_info()[1]  # works in Python 2 and 3
                  err = {'exception': exception}
                  err.update(err_env)
                  if not self.ErrorHandler(err):
                      raise
docs: urlopen(), plus error handling and possible retries.
  
          err_env is a dict of additional info passed to the error handler