def _can_retry(self, batch, error):
        """
        We can retry a send if the error is transient and the number of
        attempts taken is fewer than the maximum allowed
        """
        return (not batch.has_reached_delivery_timeout(self._accumulator.delivery_timeout_ms) and
                batch.attempts < self.config['retries'] and
                batch.final_state is None and
                getattr(error, 'retriable', False))

        We can retry a send if the error is transient and the number of
        attempts taken is fewer than the maximum allowed
        
kafka/producer/sender.py