etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
568 stars 188 forks source link

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

Open rohitsanthan opened 1 year ago

rohitsanthan commented 1 year ago

Hi, I am getting the error mentioned in the title when trying to run the below script. Could you please help with this? g = getCmd(SnmpEngine(), CommunityData("private"), UsmUserData('private', authKey='authkey1', privKey='authkey1', authProtocol=hlapi.usmHMACMD5AuthProtocol, privProtocol=hlapi.usmAesCfb128Protocol), UdpTransportTarget(('10.1.1.254', 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.4.1.9.9.23.1.3.1')))

stsojithomas commented 1 year ago

Your syntax for calling getCmd is incorrect. It seems you have mixed up Comm String along with UsmUserData which, by position, pushes UdpTransportTarget to that of ContextData parameter, and hence the error when it looks for contextName.

Please follow the correct usage for v3 and you will have it working.

Reference: https://pysnmp.readthedocs.io/en/latest/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/snmp-versions.html