Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何分配作为Python关键字的gRPC消息_Python_Protocol Buffers_Grpc_Grpc Python - Fatal编程技术网

如何分配作为Python关键字的gRPC消息

如何分配作为Python关键字的gRPC消息,python,protocol-buffers,grpc,grpc-python,Python,Protocol Buffers,Grpc,Grpc Python,我正在使用的服务有一个from消息类型 message EmailMessage { EmailRecipient from = 1; repeated EmailRecipient to = 1; .... } 下面是我如何在客户机中创建此服务请求的代码片段 email_message = eaas_pb2.EmailMessage( from=email_recipient_from,

我正在使用的服务有一个from消息类型

    message EmailMessage {
            EmailRecipient from = 1;
            repeated EmailRecipient to = 1;
            ....
    }
下面是我如何在客户机中创建此服务请求的代码片段

email_message = eaas_pb2.EmailMessage(
    from=email_recipient_from,
    to=email_recipient_to,
    subject=subject,
    purpose=purpose,
    plain_text_body=plain_text_body)
我在使用它时遇到了一个SyntaxError,因为from是一个Python关键字。 因此,protobuf已经记录了这个确切的问题。 是否有一种解决方案不涉及更改消息声明?
gPRC文档没有提到这一点。

使用kwargs字典为我解决了这个问题

 **{
        'from': email_recipient_from,
        'to': [email_recipient_to],
        'cc': [],
        'bcc': [],
        'subject': subject,
        'purpose': purpose,
        'plain_text_body': plain_text_body,
    }

用kwargs字典帮我解决了这个问题

 **{
        'from': email_recipient_from,
        'to': [email_recipient_to],
        'cc': [],
        'bcc': [],
        'subject': subject,
        'purpose': purpose,
        'plain_text_body': plain_text_body,
    }