def _message_from_exception(self, request_type, request, exc, tb=None, enc_algo=None):
        assert(enc_algo is None or enc_algo == message.PAYLOAD_ENC_CRYPTO_BOX)

        args = None
        if hasattr(exc, 'args'):
            args = list(exc.args)  # make sure tuples are made into lists

        kwargs = None
        if hasattr(exc, 'kwargs'):
            kwargs = exc.kwargs

        if tb:
            if kwargs:
                kwargs['traceback'] = tb
            else:
                kwargs = {'traceback': tb}

        if isinstance(exc, exception.ApplicationError):
            error = exc.error if type(exc.error) == six.text_type else six.u(exc.error)
        else:
            if exc.__class__ in self._ecls_to_uri_pat:
                error = self._ecls_to_uri_pat[exc.__class__][0]._uri
            else:
                error = u"wamp.error.runtime_error"

        encrypted_payload = None
        if self._keyring:
            encrypted_payload = self._keyring.encrypt(False, error, args, kwargs)

        if encrypted_payload:
            msg = message.Error(request_type,
                                request,
                                error,
                                payload=encrypted_payload.payload,
                                enc_algo=encrypted_payload.algo,
                                enc_key=encrypted_payload.pkey,
                                enc_serializer=encrypted_payload.serializer)
        else:
            msg = message.Error(request_type,
                                request,
                                error,
                                args,
                                kwargs)

        return msg
Create a WAMP error message from an exception.
dataset/ETHPy150Open crossbario/autobahn-python/autobahn/wamp/protocol.py/BaseSession._message_from_exception