Python 3.8与Protos 5.27.0兼容性问题求助
Python 3.8与Protos 5.27.0兼容性问题求助
各位大佬好,我碰到个棘手的问题想请教大家:
我正在运行一个基于Python 3.8的应用,它用到了从私有仓库生成的proto代码。之前这个集成一直都正常工作,直到生成的代码升级到5.27.0版本后,就突然出问题了。

目前我收到的报错信息如下:
Traceback (most recent call last): File "src/manage.py", line 54, in <module> execute_from_command_line(sys.argv) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute django.setup() File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/runner/work/xxx/xxx/apps/myapp/models.py", line 10, in <module> from my_proto_module import some_proto_message File "/home/runner/work/xxx/xxx/my_proto_module/__init__.py", line 3, in <module> from .proto_file_pb2 import * File "/home/runner/work/xxx/xxx/my_proto_module/proto_file_pb2.py", line 30, in <module> _descriptor.FieldDescriptor( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/google/protobuf/descriptor.py", line 561, in __new__ _message.Message._CheckCalledFromGeneratedFile() 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).
备注:内容来源于stack exchange,提问作者Xavier Garzon
相关产品推荐
相关产品推荐

