def __send_request(self, request_path, body=None, body_func=None, is_post=True, block_on_response=True):
        """Sends a request either using POST or GET to Scalyr at the specified request path.  It may be either
        a POST or GET.

        Parses, returns response.

        @param request_path: The path of the URL to post to.
        @param [body]: The body string to send.  May be None if body_func is specified.  Ignored if not POST.
        @param [body_func]:  A function that will be invoked to retrieve the body to send in the post.  Ignored if not
            POST.
        @param [is_post]:  True if this request should be sent using a POST, otherwise GET.
        @param [block_on_response]:  True if this request should block, waiting for the response.  If False, it will
            not block, but instead return a function, that will invoked, will block.

        @type request_path: str
        @type body: str|None
        @type body_func: func|None
        @type is_post: bool
        @type block_on_response: bool

        @return: If block_on_response is True, a tuple containing the status message in the response
            (such as 'success'), the number of bytes sent, and the full response.  If block_on_response is False,
            then returns a function, that will invoked, will block and return the tuple.
        @rtype: (str, int, str) or Function
        """
        current_time = time.time()

        # Refuse to try to send the message if the connection has been recently closed and we have not waited
        # long enough to try to re-open it.  We do this to avoid excessive connection opens and SYN floods.
        if self.__last_connection_close is not None and current_time - self.__last_connection_close < 30:
            return self.__wrap_response_if_necessary('client/connectionClosed', 0, '', block_on_response)

        self.total_requests_sent += 1


        was_sent = False

        try:
            try:
                if self.__connection is None:
                    self.__connection = ConnectionFactory.connection( self.__full_address, self.__request_deadline,
                                                                      self.__ca_file, self.__standard_headers,
                                                                      self.__use_requests, quiet=self.__quiet )
                    self.total_connections_created += 1
            except Exception, e:
                return self.__wrap_response_if_necessary('client/connectionFailed', 0, '', block_on_response)

            if is_post:
                if body is None:
                    body_str = body_func()
                else:
                    body_str = body
            else:
                body_str = ""

            self.total_request_bytes_sent += len(body_str) + len(request_path)

            # noinspection PyBroadException
            try:
                if is_post:
                    log.log(scalyr_logging.DEBUG_LEVEL_5, 'Sending POST %s with body \"%s\"', request_path, body_str)
                    self.__connection.post( request_path, body=body_str )
                else:
                    log.log(scalyr_logging.DEBUG_LEVEL_5, 'Sending GET %s', request_path)
                    self.__connection.get( request_path )

            except Exception, error:
                # TODO: Do not just catch Exception.  Do narrower scope.
                if hasattr(error, 'errno') and error.errno is not None:
                    log.error('Failed to connect to "%s" due to errno=%d.  Exception was %s.  Closing connection, '
                              'will re-attempt', self.__full_address, error.errno, str(error),
                              error_code='client/requestFailed')
                else:
                    log.exception('Failed to send request due to exception.  Closing connection, will re-attempt',
                                  error_code='requestFailed')
                return self.__wrap_response_if_necessary('requestFailed', len(body_str), '', block_on_response)

            was_sent = True

            def receive_response():
                return self.__receive_response(body_str, current_time)

            if not block_on_response:
                return receive_response
            else:
                return receive_response()

        finally:
            if not was_sent:
                self.total_request_latency_secs += (time.time() - current_time)
                self.total_requests_failed += 1
                self.close(current_time=current_time)
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/scalyr_client.py/ScalyrClientSession.__send_request/original