If this call came from a _pb2.py file, your generated code is out of date and must be regenerated wi

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower). 

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

找到解决方法了:

在当前conda环境下

pip uninstall protobuf

重新安装3.19.0

pip install protobuf==3.19.0

这个错误提示表示你在使用protobuf(Protocol Buffers)生成的代码时遇到了版本兼容性问题。protobuf的`_pb2.py`文件是通过protoc编译器从`.proto`协议文件生成的,当代码未与最新的protoc工具(version 3.19.0或更高版本)同步更新时会出现这种情况。以下是解决这个问题的步骤: 1. **确认protoc版本**:首先,检查你的protoc安装版本,确保它是3.19.0或以上。你可以通过命令行运行`protoc --version`来查看。 2. **升级protoc**:如果版本过低,你需要下载并安装最新版的protoc。访问protobuf官网(https://github.com/protocolbuffers/protobuf/releases)获取适合你系统的版本。 3. **更新.proto文件**:打开你的`.proto`文件,确认其中的语法和结构是否是最新的protobuf规范。 4. **重新生成代码**:使用新版protoc编译器(protoc)重新生成`_pb2.py`文件。在命令行中输入类似这样的命令: ``` protoc -I=path/to/your/proto/files --python_out=path/to/output_directory path/to/your/proto_file.proto ``` 其中`path/to/your/proto/files`是包含`.proto`文件的目录,`path/to/output_directory`是你想要保存新生成代码的位置。 5. **替换旧文件**:将新生成的`_pb2.py`文件替换掉原来的,然后重启你的应用或服务。 6. **测试代码**:最后,确认替换后的代码能否正常工作,如果没有问题,那么你就成功解决了这个问题。 如果在升级或生成过程中遇到困难,可以查阅protobuf官方文档或在线社区寻求帮助。
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值