keynote-parser icon indicating copy to clipboard operation
keynote-parser copied to clipboard

Protobufs error ("Descriptors cannot be generated directly") when running keynote-parser

Open jacobian opened this issue 2 years ago • 1 comments

$ keynote-parser unpack document.key

❯ poetry run keynote-parser
Traceback (most recent call last):
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/bin/keynote-parser", line 5, in <module>
    from keynote_parser.command_line import main
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/command_line.py", line 12, in <module>
    from .file_utils import process
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/file_utils.py", line 22, in <module>
    from .codec import IWAFile
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/codec.py", line 15, in <module>
    from .mapping import NAME_CLASS_MAP, ID_NAME_MAP
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/mapping.py", line 3, in <module>
    from .generated import KNArchives_pb2 as KNArchives
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/generated/KNArchives_pb2.py", line 16, in <module>
    from . import TSPMessages_pb2 as TSPMessages__pb2
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/keynote_parser/generated/TSPMessages_pb2.py", line 32, in <module>
    _descriptor.EnumValueDescriptor(
  File "/Users/jacob/Library/Caches/pypoetry/virtualenvs/jacobian-dot-org-j3R1CXE--py3.9/lib/python3.9/site-packages/google/protobuf/descriptor.py", line 755, 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).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

As the error message suggested, setting PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python works, so this is trivial to work around, but I guess maybe indicates something wrong?

My system:

  • macOS 12.3.1
  • Keynote 12.0
  • Python 3.9.4
  • keynote-parser 1.23.0.0, which installed:
    • protobuf 4.21.1
    • python-snappy 0.6.1
    • (and a few others that I think are irrelevant)

jacobian avatar Jun 01 '22 14:06 jacobian

Similar error with Keynote 12.1, in Mac 12.4

jvallef avatar Jun 23 '22 17:06 jvallef

Hi @jacobian and @jvallef! This has been fixed in v1.12.1.0, which also adds support for Keynote 12.1.

The root cause was that the version of protoc used to generate the _pb2.py files included in keynote-parser was older than v3.20.0, in which new breaking changes were introduced.

psobot avatar Sep 18 '22 22:09 psobot