From be7de7d7a72ed73777bcae6eff0ba0f698172548 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Sun, 23 Jun 2019 09:04:26 +0200 Subject: Fix `var-bindings` initialization Set `var-bindings` to an empty sequence by default. Otherwise it can remain a "pyasn1 schema object" failing to encode. This can happen with newer pyasn1 versions where `SequenceOf` type does not have default initializer. --- pysnmp/proto/api/v1.py | 7 +++++-- pysnmp/proto/api/v2c.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'pysnmp') diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py index f13920e7..e8641deb 100644 --- a/pysnmp/proto/api/v1.py +++ b/pysnmp/proto/api/v1.py @@ -80,7 +80,9 @@ class PDUAPI(object): 2, self._errorIndex, verifyConstraints=False, matchTags=False, matchConstraints=False) - pdu.setComponentByPosition(3) + varBindList = pdu.setComponentByPosition(3).getComponentByPosition(3) + varBindList.clear() + @staticmethod def getRequestID(pdu): @@ -217,7 +219,8 @@ class TrapPDUAPI(object): 4, self._zeroTime, verifyConstraints=False, matchTags=False, matchConstraints=False) - pdu.setComponentByPosition(5) + varBindList = pdu.setComponentByPosition(5).getComponentByPosition(5) + varBindList.clear() @staticmethod def getEnterprise(pdu): diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py index c415ca9a..0470fafd 100644 --- a/pysnmp/proto/api/v2c.py +++ b/pysnmp/proto/api/v2c.py @@ -119,7 +119,8 @@ class BulkPDUAPI(PDUAPI): 2, self._maxRepetitions, verifyConstraints=False, matchTags=False, matchConstraints=False) - pdu.setComponentByPosition(3) + varBindList = pdu.setComponentByPosition(3).getComponentByPosition(3) + varBindList.clear() @staticmethod def getNonRepeaters(pdu): -- cgit v1.2.1