CiscoDevNet / xr-gnmi-lab

Understand gNMI and how to build your first gNMI client with Python to interwork with IOS-XR
Apache License 2.0
5 stars 0 forks source link

from cisco_gnmi import ClientBuilder #1

Closed sbyount closed 1 year ago

sbyount commented 1 year ago

This import generates the following error in Jupyter notebook with python 3.9.5 installed, with a suggestion to downgrade the protobuf package to 3.20.x or lower.

Package Version


cisco-gnmi 1.0.16 grpcio 1.50.0 protobuf 4.21.9


TypeError Traceback (most recent call last) Cell In [2], line 1 ----> 1 from cisco_gnmi import ClientBuilder

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/init.py:27 1 """Copyright 2019 Cisco Systems 2 All rights reserved. 3 (...) 21 the License. 22 """ 24 """This library wraps gNMI functionality to ease usage in Python programs.""" ---> 27 from .client import Client 28 from .xr import XRClient 29 from .nx import NXClient

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/client.py:30 27 from xml.etree.ElementPath import xpath_tokenizer_re 28 from six import string_types ---> 30 from . import proto 31 from . import util 34 LOGGER = logging.getLogger(name)

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/proto/init.py:25 1 """Copyright 2019 Cisco Systems 2 All rights reserved. 3 (...) 21 the License. 22 """ ---> 25 from . import gnmi_pb2_grpc 26 from . import gnmi_pb2

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/proto/gnmi_pb2_grpc.py:4 1 # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 import grpc ----> 4 from . import gnmi_pb2 as gnmi__pb2 7 class gNMIStub(object): 8 # missing associated documentation comment in .proto file 9 pass

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/proto/gnmi_pb2.py:19 17 from google.protobuf import any_pb2 as google_dot_protobuf_dot_anypb2 18 from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptorpb2 ---> 19 from . import gnmi_ext_pb2 as gnmiext__pb2 22 DESCRIPTOR = _descriptor.FileDescriptor( 23 name='gnmi.proto', 24 package='gnmi', (...) 28 , 29 dependencies=[google_dot_protobuf_dot_anypb2.DESCRIPTOR,google_dot_protobuf_dot_descriptorpb2.DESCRIPTOR,gnmiext__pb2.DESCRIPTOR,]) 31 _ENCODING = _descriptor.EnumDescriptor( 32 name='Encoding', 33 full_name='gnmi.Encoding', (...) 61 serialized_end=3485, 62 )

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/cisco_gnmi/proto/gnmi_ext_pb2.py:33 14 _sym_db = _symbol_database.Default() 19 DESCRIPTOR = _descriptor.FileDescriptor( 20 name='gnmi_ext.proto', 21 package='gnmi_ext', (...) 24 serialized_pb=_b('\n\x0egnmi_ext.proto\x12\x08gnmi_ext\"\x86\x01\n\tExtension\x12\x37\n\x0eregistered_ext\x18\x01 \x01(\x0b\x32\x1d.gnmi_ext.RegisteredExtensionH\x00\x12\x39\n\x12master_arbitration\x18\x02 \x01(\x0b\x32\x1b.gnmi_ext.MasterArbitrationH\x00\x42\x05\n\x03\x65xt\"E\n\x13RegisteredExtension\x12!\n\x02id\x18\x01 \x01(\x0e\x32\x15.gnmi_ext.ExtensionID\x12\x0b\n\x03msg\x18\x02 \x01(\x0c\"Y\n\x11MasterArbitration\x12\x1c\n\x04role\x18\x01 \x01(\x0b\x32\x0e.gnmi_ext.Role\x12&\n\x0b\x65lection_id\x18\x02 \x01(\x0b\x32\x11.gnmi_ext.Uint128\"$\n\x07Uint128\x12\x0c\n\x04high\x18\x01 \x01(\x04\x12\x0b\n\x03low\x18\x02 \x01(\x04\"\x12\n\x04Role\x12\n\n\x02id\x18\x01 \x01(\t*3\n\x0b\x45xtensionID\x12\r\n\tEID_UNSET\x10\x00\x12\x15\n\x10\x45ID_EXPERIMENTAL\x10\xe7\x07\x62\x06proto3') 25 ) 27 _EXTENSIONID = _descriptor.EnumDescriptor( 28 name='ExtensionID', 29 full_name='gnmi_ext.ExtensionID', 30 filename=None, 31 file=DESCRIPTOR, 32 values=[ ---> 33 _descriptor.EnumValueDescriptor( 34 name='EID_UNSET', index=0, number=0, 35 serialized_options=None, 36 type=None), 37 _descriptor.EnumValueDescriptor( 38 name='EID_EXPERIMENTAL', index=1, number=999, 39 serialized_options=None, 40 type=None), 41 ], 42 containing_type=None, 43 serialized_options=None, 44 serialized_start=385, 45 serialized_end=436, 46 ) 47 _sym_db.RegisterEnumDescriptor(_EXTENSIONID) 49 ExtensionID = enum_type_wrapper.EnumTypeWrapper(_EXTENSIONID)

File ~/code/xr-gnmi-lab/venv/lib/python3.9/site-packages/google/protobuf/descriptor.py:755, in EnumValueDescriptor.new(cls, name, index, number, type, options, serialized_options, create_key) 752 def new(cls, name, index, number, 753 type=None, # pylint: disable=redefined-builtin 754 options=None, serialized_options=None, create_key=None): --> 755 _message.Message._CheckCalledFromGeneratedFile() 756 # There is no way we can build a complete EnumValueDescriptor with the 757 # given parameters (the name of the Enum is not known, for example). 758 # Fortunately generated files just pass it to the EnumDescriptor() 759 # constructor, which will ignore it, so returning None is good enough. 760 return None

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

cprecup commented 1 year ago

Hello @sbyount - thanks for raising this issue.

This seems to be related to the cisco-gnmi library. Could you raise the issue for that project, if this has not been resolved? Here is the repository: https://github.com/cisco-ie/cisco-gnmi-python.