栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python使用protobuf格式通信(遇到的坑)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python使用protobuf格式通信(遇到的坑)

1、安装

使用清华源进行安装

pip3 install https://pypi.tuna.tsinghua.edu.cn/simple grpcio  grpcio-tools  protobuf
坑:根据.proto文件转化时报错,但grpc-tools安装成功了
Error while finding module specification for 'grpc_tools.protoc' 
(ModuleNotFoundError: No module named 'grpc_tools')

解决:

应该安装grpcio-tools,安装grpcio-tools时有的会报错

需要设置信任源即可:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn grpcio-tools
2、编写proto配置文件
syntax = "proto3";

package format;

message Request {
    string id = 1;
    string data = 2;
}

message Response {
    int32 code = 1;
    string id = 2;
    string data = 3;
}
3、自动生成代码
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. format.proto
4、应用
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/656827.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号