Nitropy / nk3: new error with _pb2.py

Recently (probably after a system upgrade), I have been getting an error running:

nitropy nk3 secrets get-password $PWID

Traceback (most recent call last):
  File "/usr/bin/nitropy", line 5, in <module>
    from pynitrokey.cli import main
  File "/usr/lib/python3.12/site-packages/pynitrokey/cli/__init__.py", line 26, in <module>
    from pynitrokey.cli.nk3 import nk3
  File "/usr/lib/python3.12/site-packages/pynitrokey/cli/nk3/__init__.py", line 19, in <module>
    from pynitrokey.nk3 import NK3_DATA
  File "/usr/lib/python3.12/site-packages/pynitrokey/nk3/__init__.py", line 14, in <module>
    from pynitrokey.trussed.bootloader.nrf52 import SignatureKey
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52.py", line 29, in <module>
    from .nrf52_upload.dfu.init_packet_pb import InitPacketPB
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52_upload/dfu/init_packet_pb.py", line 39, in <module>
    from . import dfu_cc_pb2 as pb
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52_upload/dfu/dfu_cc_pb2.py", line 34, in <module>
    _descriptor.EnumValueDescriptor(
  File "/usr/lib/python3.12/site-packages/google/protobuf/descriptor.py", line 920, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot 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

On one hand, I can simply set export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python on my system and everything works, however I would like to resolve the issue and based on the file-paths it seems like this might be something that should be solved by pynitrokey.

Someone already added an issue for it at dfu_cc_pb2.py incompatible with recent protobuf version · Issue #548 · Nitrokey/pynitrokey · GitHub
(even with a fix proposal) and Nitrokey acknowledged existence. Best to watch that space.

1 Like