Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'UdpTransportTarget' object has no attribute 'contextName' #447

Open
HasnaARajdal opened this issue Aug 4, 2023 · 2 comments

Comments

@HasnaARajdal
Copy link

Hi, I am getting the error mentioned in the title when trying to run the below script. Could you please help with this?
from pysnmp.hlapi import *

`community_string = 'public'

oid = '1.3.6.1.4.1.259.10.1.45.1.2.6.1.4.9'
ip_address = '192.168.1.250'

def get_inpututil():

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData(community_string),
           UdpTransportTarget((ip_address, 161)),
           ContextData(),
           ObjectType(ObjectIdentity(oid)))
)
for varBind in varBinds:
    print('Util = {} %'.format(varBind[1]/100))

if name == 'main':
get_inpututil()`

@lextm
Copy link

lextm commented Aug 4, 2023

If you switch to PySNMP 5 (package pysnmp-lextudio), the script can be further simplified,

http://www.pysnmp.com/pysnmp/quick-start#fetch-snmp-variable

Read #429 to learn more.

@HasnaARajdal
Copy link
Author

a friend of mine tried this code and it works for him so i think it is a version problem of package and python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants