【问题标题】:How to assign gRPC message which is a Python keyword如何分配作为 Python 关键字的 gRPC 消息
【发布时间】:2020-08-20 12:28:35
【问题描述】:

我正在使用的服务具有 from 消息类型。

    message EmailMessage {
            EmailRecipient from = 1;
            repeated EmailRecipient to = 1;
            ....
    }

这是我如何在我的客户端中创建此服务的请求的代码 sn-p。

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 here 中。 是否有不涉及更改消息声明的解决方案? gPRC 文档没有提及这方面的任何内容。

【问题讨论】:

    标签: python protocol-buffers grpc grpc-python


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      • 2018-05-29
      • 2013-01-21
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多