如何使用python增加grpc中的消息大小

Dum*_*mbo 7 python client message server grpc

我正在使用grpc进行消息传递,并正在测试一个简单的服务器和客户端.当我的邮件大小超过限制时,我收到此错误.

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with 
(StatusCode.INVALID_ARGUMENT,
 Received message larger than max (7309898 vs. 4194304))>
Run Code Online (Sandbox Code Playgroud)

如何在服务器和客户端增加邮件大小?

小智 16

我遇到了这个问题,我通过在客户端和服务器上设置“grpc.max_send_message_length”和“grpc.max_receive_message_length”来解决它:

在客户端中(此代码片段归功于@Dumbo):

channel = grpc.insecure_channel(
    'localhost:50051',
    options=[
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
    ],
)
Run Code Online (Sandbox Code Playgroud)

在服务器中:

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options = [
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)
    ])
Run Code Online (Sandbox Code Playgroud)


Dum*_*mbo 7

改变message_length的同时发送和接收会做的伎俩。

channel = grpc.insecure_channel(
    'localhost:50051',
    options=[
        ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
        ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
    ],
)
Run Code Online (Sandbox Code Playgroud)