PYSNMP:pyasn1。error.SubstrateUnderrunError:37998八位字节sh

2024-10-04 03:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有python版本4.3.2、py2exe 0.9.1.0、pysnmp 0.4.3.1、pyans1 0.1.9。
我在许多不同的客户机上遇到了所有类型的不一致错误。
所有SNMP设备中都有一个SNMP设备,这些设备阻止了所有SNMP设备br/> 这是函数:

def cbFun_Device(transportDispatcher, transportDomain, transportAddress, wholeMsg):
    while wholeMsg:
        for ip in Device.scan.devices:
            if ip == transportAddress[0]:
                try:
                    PDU = Device.scan.devices[ip].PDU
                    rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec = PDU['pMod'].Message())
                    rspPDU = PDU['pMod'].apiMessage.getPDU(rspMsg)
                    # Match response to request
                    if PDU['pMod'].apiPDU.getRequestID(PDU['reqPDU']) == PDU['pMod'].apiPDU.getRequestID(rspPDU):
                        errorStatus = PDU['pMod'].apiPDU.getErrorStatus(rspPDU)
                        if not (errorStatus and errorStatus != 2):
                            PDUarr = []
                            varBindTable = PDU['pMod'].apiPDU.getVarBindTable(PDU['reqPDU'], rspPDU)
                            for tableRow in varBindTable:
                                for oid, val in tableRow:
                                    print('from: %s, %s = %s' % (transportAddress, oid.prettyPrint(), val.prettyPrint()))
                                    if str(oid.prettyPrint()) not in Device.scan.params['MIBs']:
                                        for mibOID in PDU['MIBs']:
                                            if str(oid.prettyPrint()).find(mibOID) != -1 and mibOID not in Device.scan.devices[ip].MIBs:
                                                Device.scan.devices[ip].MIBs.append(mibOID)
                                    for tree in PDU['OIDs']:
                                        if str(oid.prettyPrint()).find(tree) != -1 and str(oid.prettyPrint()) not in Device.scan.devices[ip].OIDs:
                                            Device.scan.devices[ip].OIDs[str(oid.prettyPrint())] = val.prettyPrint()[:-1][2:] if val.prettyPrint().startswith("b'") and val.prettyPrint().endswith("'") else val.prettyPrint()
                                            PDUarr.append((str(oid.prettyPrint()), PDU['pMod'].null))
                            # Stop on EOM
                            for oid, val in varBindTable[-1]:
                                if not isinstance(val, PDU['pMod'].Null):
                                    break
                            else:
                                Progress.networks[ip]['Done'] = True
                                print("IP-------- " + ip)
                                Progress.progress.append(1)
                                Device.transportDispatcher.jobFinished(1)
                                continue    
                            # Generate request for next row
                            print(PDUarr)
                            if PDUarr != []:
                                PDU['pMod'].apiPDU.setVarBinds(PDU['reqPDU'], PDUarr)
                                PDU['pMod'].apiPDU.setRequestID(PDU['reqPDU'], PDU['pMod'].getNextRequestID())
                                Device.transportDispatcher.sendMessage(
                                    encoder.encode(PDU['reqMsg']), transportDomain, transportAddress
                                    )
                                Progress.networks[ip]['Time'] = time.time()
                            else:
                                Progress.networks[ip]['Done'] = True
                                print("IP-------- " + ip)
                                Progress.progress.append(1)
                                Device.transportDispatcher.jobFinished(1)
                                continue

这是我收到的错误:

^{pr2}$

有时也会出现这样的错误:

  pyasn1.error.PyAsn1Error: Empty substrate

但所有的错误都发生在这条线上:

rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec = PDU['pMod'].Message())

怎么回事?在


Tags: inipforscanifdevicevalpdu