status = StatusCode.RESOURCE_EXHAUSTED
details = "Received message larger than max (4282239 vs. 4194304)"
debug_error_string = "{"created":"@1633745838.187727309","description":"Received message larger than max (4282239 vs. 4194304)"
grpc 默认的传输长度是4M,当超过4M时会出现上面的错误。需要定制传输参数。
从server端和client端都需要指定传输参数如下:
在server端 设置 server参数:
MAX_MESSAGE_LENGTH = 256*1024*1024 # 可根据具体需求设置,此处设为256M
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),
]
# compression=grpc.Compression.Gzip,
# interceptors=...,
)
在client端设置channel参数:
MAX_MESSAGE_LENGTH = 256*1024*1024 # 可根据具体需求设置,此处设为256M
with grpc.insecure_channel(target=docker_channel, options=[
('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
]
# compression=grpc.Compression.Gzip,
) as channel:
如果开发语言采用的是C++, 可参考
python grpc报错Received message larger than max_liyangbinbin的博客-CSDN博客