File: non-printable-snmp-values-apps.rst

package info (click to toggle)
python-pysnmp4 4.4.6%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,388 kB
  • sloc: python: 19,792; makefile: 166; sh: 23
file content (40 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

Garbaged SNMP values (apps)
---------------------------

Q. When my PySNMP application prints out fetched values, some of them 
   come out as a garbage on my screan. Here's my code:

.. code-block:: python

    for varBind in varBinds:
      print(' = '.join([ str(x) for x in varBind ])

   and the result is:

.. code-block:: python

    1.3.6.1.4.1.161.19.3.2.1.63.0 = 50000
    1.3.6.1.4.1.161.19.3.2.1.4.0 = '\x01\x02\x03\x04'

   The IpAddress type seems to be the only one with this problem.

A. Always use prettyPrint() method for all pyasn1-based objects -- it 
   automatically converts ASN1 types to human-friendly form.

.. code-block:: python

    > > > from pysnmp.proto import rfc1902
    > > > a = rfc1902.IpAddress('1.2.3.4')
    > > > str(a)
    '\x01\x02\x03\x04'
    > > > a
    IpAddress('1.2.3.4')
    > > > a.prettyPrint()
    '1.2.3.4'
    > > > rfc1902.IpAddress.prettyPrint(a)
    '1.2.3.4'

See `pyasn1 docs <http://snmplabs.com/pyasn1/>`_ for more information
on pyasn1 data model.