Answer the question
In order to leave comments, you need to log in
Why doesn't the simplest example from the easysnmp library work?
In general, I decided to understand the SNMP protocol. What's what and so on. After reading a little theory and understanding the very basics, I decided to quickly start practicing in Python. But something went wrong: even the simplest example from the official documentation does not work.
from easysnmp import Session
# Create an SNMP session to be used for all our requests
session = Session(hostname='localhost', community='public', version=2)
# You may retrieve an individual OID using an SNMP GET
location = session.get('sysLocation.0')
# You may also specify the OID as a tuple (name, index)
# Note: the index is specified as a string as it can be of other types than
# just a regular integer
contact = session.get(('sysContact', '0'))
# And of course, you may use the numeric OID too
description = session.get('.1.3.6.1.2.1.1.1.0')
# Set a variable using an SNMP SET
session.set('sysLocation.0', 'The SNMP Lab')
# Perform an SNMP walk
system_items = session.walk('system')
# Each returned item can be used normally as its related type (str or int)
# but also has several extended attributes with SNMP-specific information
for item in system_items:
print '{oid}.{oid_index} {snmp_type} = {value}'.format(
oid=item.oid,
oid_index=item.oid_index,
snmp_type=item.snmp_type,
value=item.value
)
Traceback (most recent call last):
File "/home/meksvinz/PycharmProjects/easysnmp/1.py", line 4, in <module>
snmp_get('sysDescr.0', hostname='localhost', community='public', version=1)
File "/home/meksvinz/projects/envs/snmp/lib/python3.7/site-packages/easysnmp/easy.py", line 22, in snmp_get
return session.get(oids)
File "/home/meksvinz/projects/envs/snmp/lib/python3.7/site-packages/easysnmp/session.py", line 315, in get
interface.get(self, varlist)
SystemError: <built-in function get> returned NULL without setting an error
Answer the question
In order to leave comments, you need to log in
There's a compatibility bug with python3.7 at the C level of the module. I was looking for how to fix this some time ago, and I managed to fix it. The patch is here: https://github.com/kamakazikamikaze/easysnmp/pull/117
And you can install the corrected one for python3.7 here: https://github.com/nerosketch/easysnmp.git.
pip install git+ https://github.com/nerosketch/easysnmp.git
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question