Reputation: 3088
I'm trying to use val.prettyPrint()
in Python 3.4.2 using Pysnmp 4.3.1 to read the values of the OIDs. val.prettyPrint()
returns a string for any type of variable. So I receive this value "b'zeus.snmplabs.com'"
as of type string instead of type bytes. So when I send this data to a server, it treats the b
prefix as part of the string. Is this a bug or functionality intentional?
Upvotes: 1
Views: 367
Reputation: 5555
This is a bug (actually, in pyasn1), however development pysnmp code has a workaround in place.
Keep in mind that in SNMP (and ASN.1) OCTET STRING type is supposed to carry bytes, not text. Therefore .prettyPrint() tries to represent value as printable 7-bit ASCII string if possible. Otherwise it switches to hex representation (0xdeadbeef).
SNMP objects that should carry text are usually explicitly typed as TEXTUAL-CONVENTION objects in MIBs. Based on MIB information SNMP manager would "cast" protocol-level OCTET STRING values into a printable in specified encoding (ASCII or UTF-8) ignoring all non-printable characters along the way.
Upvotes: 1