像对象这样的字节是必需的,不是字符串错误

时间:2019-04-21 09:56:54

标签: python python-3.x networking ospf

这段代码中的错误

errorIndication,errorStatus,errorIndex,varBindNbrTable = cmdGen.nextCmd(cmdgen.CommunityData(comm),                                                                                    cmdgen.UdpTransportTarget((ip.encode(“ ascii”),161)),                                                                                    '1.3.6.1.2.1.14.10.1.3')

    print(varBindNbrTable)
    print("oo")
    errorIndication, errorStatus, errorIndex, varBindNbrIpTable = cmdGen.nextCmd(cmdgen.CommunityData(comm),
                                                                                 cmdgen.UdpTransportTarget(
                                                                                     (ip.encode("ascii"), 161)),
                                                                                 '1.3.6.1.2.1.14.10.1.1')

    errorIndication, errorStatus, errorIndex, varBindHostTable = cmdGen.nextCmd(cmdgen.CommunityData(comm),
                                                                                cmdgen.UdpTransportTarget(
                                                                                    (ip.encode("ascii"), 161)),
                                                                                '1.3.6.1.4.1.9.2.1.3')

    errorIndication, errorStatus, errorIndex, varBindHostIdTable = cmdGen.nextCmd(cmdgen.CommunityData(comm),
                                                                                  cmdgen.UdpTransportTarget(
                                                                                      (ip.encode("ascii"), 161)),
                                                                                  '1.3.6.1.2.1.14.1.1')

    print(varBindHostIdTable)
    # xtract and print out the results
    for varBindNbrTableRow in varBindNbrTable:
        for oid, nbrid in varBindNbrTableRow:
            hex_string = binascii.hexlify(str(nbrid)).encode("utf-8")
            print(hex_string)
            print("o1")
            octets = [hex_string[i:i + 2] for i in range(0, len(hex_string), 2)]
            print(octets)
            print("o2")
            ip = [int(i, 16) for i in octets]
            print(ip)
            nbr_r_id = '.'.join(str(i) for i in ip)
            print(nbr_r_id)
            nbridlist.append(nbr_r_id)
            print('%s = %s' % (oid, nbr_r_id))

0 个答案:

没有答案