I'm trying to use snmp 0.5.0 inside a docker container with Ubuntu and Python 3.11.3 installed.
When I try to execute the following code from the documentation:
from snmp import Engine, SNMPv2c
with Engine(SNMPv2c, defaultCommunity="public") as engine:
localhost = engine.Manager("127.0.0.1")
response = localhost.get("1.3.6.1.2.1.1.4.0", "1.3.6.1.2.1.1.6.0")
print(response)
I receive the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 5
3 with Engine(SNMPv2c, defaultCommunity="public") as engine:
4 localhost = engine.Manager("127.0.0.1")
----> 5 response = localhost.get("1.3.6.1.2.1.1.4.0", "1.3.6.1.2.1.1.6.0")
6 print(response)
File /opt/conda/lib/python3.11/site-packages/snmp/manager/v2c.py:164, in SNMPv2cManager.get(self, *oids, **kwargs)
162 def get(self, *oids, **kwargs):
163 pdu = GetRequestPDU(*oids)
--> 164 return self.sendRequest(pdu, **kwargs)
File /opt/conda/lib/python3.11/site-packages/snmp/manager/v2c.py:155, in SNMPv2cManager.sendRequest(self, pdu, community, wait, **kwargs)
153 with self.lock:
154 heapq.heappush(self.requests, reference)
--> 155 request.send()
157 if wait:
158 return request.wait()
File /opt/conda/lib/python3.11/site-packages/snmp/manager/v2c.py:86, in Request.send(self)
84 now = time.time()
85 self.nextRefresh = now + self.period
---> 86 self.reallySend()
File /opt/conda/lib/python3.11/site-packages/snmp/manager/v2c.py:62, in Request.reallySend(self)
61 def reallySend(self):
---> 62 self.manager.sendPdu(self.pdu, self, self.community)
File /opt/conda/lib/python3.11/site-packages/snmp/manager/v2c.py:135, in SNMPv2cManager.sendPdu(self, pdu, handle, community)
134 def sendPdu(self, pdu, handle, community):
--> 135 self.dispatcher.sendPdu(
136 self.locator,
137 MessageProcessingModel.SNMPv2c,
138 pdu,
139 handle,
140 community,
141 )
File /opt/conda/lib/python3.11/site-packages/snmp/dispatcher.py:87, in Dispatcher.sendPdu(self, locator, mpm, pdu, handle, *args, **kwargs)
84 mpm = str(MessageProcessingModel(mpm))
85 raise ValueError("{} is not enabled".format(mpm)) from err
---> 87 msg = mp.prepareOutgoingMessage(pdu, handle, *args, **kwargs)
88 transport.send(locator.address, msg)
File /opt/conda/lib/python3.11/site-packages/snmp/message/v2c.py:111, in SNMPv2cMessageProcessor.prepareOutgoingMessage(self, pdu, handle, community)
108 pdu.requestID = self.cache(cacheEntry)
109 handle.addCallback(self.uncache, pdu.requestID)
--> 111 return Message(self.VERSION, community, pdu).encode()
File /opt/conda/lib/python3.11/site-packages/snmp/types.py:76, in Asn1Encodable.encode(self)
75 def encode(self) -> bytes:
---> 76 return encode(self.TYPE, self.serialize())
File /opt/conda/lib/python3.11/site-packages/snmp/types.py:499, in Constructed.serialize(self)
498 def serialize(self) -> bytes:
--> 499 return b"".join([item.encode() for item in self])
File /opt/conda/lib/python3.11/site-packages/snmp/types.py:499, in <listcomp>(.0)
498 def serialize(self) -> bytes:
--> 499 return b"".join([item.encode() for item in self])
File /opt/conda/lib/python3.11/site-packages/snmp/types.py:76, in Asn1Encodable.encode(self)
75 def encode(self) -> bytes:
---> 76 return encode(self.TYPE, self.serialize())
File /opt/conda/lib/python3.11/site-packages/snmp/ber.py:281, in encode(identifier, data)
279 def encode(identifier: Identifier, data: bytes) -> bytes:
280 """Encode a message under ASN.1 Basic Encoding Rules."""
--> 281 return identifier.encode() + encode_length(len(data)) + data
TypeError: can't concat str to bytes
Do you know how may I solve it or what may cause it?
Thanks!
Hi!
I'm trying to use snmp 0.5.0 inside a docker container with Ubuntu and Python 3.11.3 installed. When I try to execute the following code from the documentation:
I receive the following error:
Do you know how may I solve it or what may cause it? Thanks!