如何分配作为Python关键字的gRPC消息
我正在使用的服务有一个from消息类型如何分配作为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,
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,
}