2012-01-21 31 views
1

我下面舉個例子從pysnmp頁: #GET命令產生 從pysnmp.entity.rfc3413.oneliner進口cmdgenPySNMP:加載錯誤:錯誤的八位位組初始化

errorIndication, errorStatus, \ 
       errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
    # SNMP v1 
# cmdgen.CommunityData('test-agent', 'public', 0), 
    # SNMP v2 
    cmdgen.CommunityData('test-agent', 'public'), 
    # SNMP v3 
# cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'), 
    cmdgen.UdpTransportTarget(('localhost', 161)), 
    # Plain OID 
    (1,3,6,1,2,1,1,1,0), 
    # ((mib-name, mib-symbol), instance-id) 
    (('SNMPv2-MIB', 'sysDescr'), 0) 
    ) 

if errorIndication: 
    print errorIndication 
else: 
    if errorStatus: 
     print '%s at %s\n' % (
      errorStatus.prettyPrint(), 
      errorIndex and varBinds[int(errorIndex)-1] or '?' 
      ) 
    else: 
     for name, val in varBinds: 
      print '%s = %s' % (name.prettyPrint(), val.prettyPrint()) 

我確信,SNMP是在我的機器上運行。我使用以下命令檢查了控制檯:

snmpget -v2c -Cf -c public localhost 1.3.6.1.2.1.1.1.0 

哪些工作正常。 如果上述我得到以下錯誤我執行Python代碼:

SmiError: MIB module "pysnmp/smi/mibs/SNMP-COMMUNITY-MIB.py" load error: MIB module "pysnmp/smi/mibs/SNMP-FRAMEWORK-MIB.py" load error: Bad OctetString initializer '[128, 0, 79, 184, 5, 192, 168, 1, 50, 371, 210, 26, 162, 157]' 

的數字在每個執行結束變化(似乎時間戳或服用點那樣)。 我使用python 2.7和最新的pySNMP(4.2.1)的版本。 有誰知道什麼是與此示例代碼的問題?

回答