You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get information from some printers using SNMP. I followed the steps in the official documentation, but when I run the code, it always says: "module 'pysnmp.hlapi' has no attribute 'getCmd'."
This is my code below:
import pysnmp.hlapi as hlapi
# OIDs Comuns
SerialNumber = '1.3.6.1.2.1.43.5.1.1.17.1'
totalPageCounter = '1.3.6.1.2.1.43.10.2.1.4.1.1'
tonerLevel = '1.3.6.1.2.1.43.11.1.1.9.1.1'
def get_snmp_data(ip, community, oid):
for (errorIndication, errorStatus, errorIndex, varBinds) in hlapi.getCmd(
hlapi.SnmpEngine(),
hlapi.CommunityData(community, mpModel=0), # mpModel=0 para SNMPv1 ou mpModel=1 para SNMPv2c
hlapi.UdpTransportTarget((ip, 161)),
hlapi.ContextData(),
hlapi.ObjectType(hlapi.ObjectIdentity(oid))
):
if errorIndication:
print(f"Erro: {errorIndication}")
return None
elif errorStatus:
print(f"Erro no status: {errorStatus.prettyPrint()} em {errorIndex}")
return None
else:
for var_bind in varBinds:
return var_bind[1].prettyPrint()
def main():
print(get_snmp_data("192.168.1.150", "public", SerialNumber))
if __name__ == "__main__":
main()
I'm using a Windows 10 system.
The text was updated successfully, but these errors were encountered:
Good afternoon!
I'm trying to get information from some printers using SNMP. I followed the steps in the official documentation, but when I run the code, it always says: "module 'pysnmp.hlapi' has no attribute 'getCmd'."
This is my code below:
I'm using a Windows 10 system.
The text was updated successfully, but these errors were encountered: