Re: [pysnmp-users] pysnmp / pyasn1 decode problem with multi-line traps
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2015-03-11 13:17:31
|
That's right, .asOctets() is only defined for OctetString type and its subclasses. Therefore, to deal with octets of OctetString() you should do additional check: from pysnmp.proto.rfc1902 import OctetString ... if isinstance(val, OctetString): val = val.asOctets() Keep in mind that octet string is not always the same as printable string. The former is not immune to your terminal potentially eating non-printable characters or garbling output in a funny way. Also, text encoding is not defined by OctetString. To be on a safe side default OctetString printout is done in hex whenever a non-printable is seen in its contents. -ilya On 03/11/2015 03:18 PM, Craig Small wrote: > On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' > Are you sure each row is returning something asOctets makes sense for? > An Integer doesn't make sense. > >> Does it only works if a hex value is send by snmp? > I believe it works for certain types of values, such as an OctetString > >> How can I check if the value is hex or not? > Not sure, but the types are found in pyasn1.type.univ so you could > compare it to, say, univ.OctetString > > ObjectSyntax seems to be the superset of all types, from what I can tell > it means pysnmp wasn't sure what the type should be. > > It's been an interesting and educational discussion anyhow. > > - Craig |