报错:
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).
More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
解法方法:
降低protobuf的版本:
pip uninstall protobuf
pip install protobuf==3.20.1
在使用protobuf时遇到TypeError,提示不能直接创建Descriptors。错误原因可能是protobuf版本过低或过高。解决方案包括升级到protoc 3.19.0以上或者降级protobuf到3.20.1。此外,还可以通过设置环境变量PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION为python来使用纯Python解析,但速度会变慢。更多信息可参考官方文档。
3238

被折叠的 条评论
为什么被折叠?



