def __receive_response(self, body_str, send_time):
        """Receives a response for a request previously sent using __send_request.

        @param body_str: The body of the request that was sent.
        @param send_time: The time of day when the request was sent.

        @type body_str: str
        @type send_time: float
        @return:  The tuple containing the status message in the response  (such as 'success'), the number of bytes
            sent, and the full response.
        @rtype: (str, int, str)
        """
        response = ''
        was_success = False
        bytes_received = 0

        try:
            try:
                status_code = self.__connection.status_code()
                response = self.__connection.response()
                bytes_received = len(response)
            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 receive response 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 receive response due to exception.  Closing connection, will re-attempt',
                                  error_code='requestFailed')
                return 'requestFailed', len(body_str), response

            log.log(scalyr_logging.DEBUG_LEVEL_5, 'Response was received with body \"%s\"', response)

            if status_code == 429:
                log.error('Received "too busy" response from server.  Will re-attempt',
                          error_code='serverTooBusy')
                return 'serverTooBusy', len(body_str), response

            # If we got back an empty result, that often means the connection has been closed or reset.
            if len(response) == 0:
                log.error('Received empty response, server may have reset connection.  Will re-attempt',
                          error_code='emptyResponse')
                return 'emptyResponse', len(body_str), response

            # Try to parse the response
            # noinspection PyBroadException
            try:
                response_as_json = json_lib.parse(response)
            except Exception:
                # TODO: Do not just catch Exception.  Do narrower scope.  Also, log error here.
                log.error('Failed to parse response of \'%s\' due to exception.  Closing connection, will '
                          're-attempt', scalyr_util.remove_newlines_and_truncate(response, 1000),
                          error_code='parseResponseFailed')
                return 'parseResponseFailed', len(body_str), response

            self.__last_success = send_time

            if response_as_json in 'status':
                status = response_as_json['status']
                if status == 'success':
                    was_success = True
                elif status == 'error/client/badParam':
                    log.error('Request to \'%s\' failed due to a bad parameter value.  This may be caused by an '
                              'invalid write logs api key in the configuration', self.__full_address,
                              error_code='error/client/badParam')
                else:
                    log.error('Request to \'%s\' failed due to an error.  Returned error code was \'%s\'',
                              self.__full_address, status, error_code='error/client/badParam')
                return status, len(body_str), response
            else:
                log.error('No status message provided in response.  Unknown error.  Response was \'%s\'',
                          scalyr_util.remove_newlines_and_truncate(response, 1000), error_code='unknownError')
                return 'unknownError', len(body_str), response

        finally:
            self.total_request_latency_secs += (time.time() - send_time)
            if not was_success:
                self.total_requests_failed += 1
                self.close(current_time=send_time)
            self.total_response_bytes_received += bytes_received
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/scalyr_client.py/ScalyrClientSession.__receive_response/swapped operands of `in`