Python/Netmiko:在交换机日志中查找故障

Python/Netmiko:在交换机日志中查找故障,python,networking,scripting,instance,netmiko,Python,Networking,Scripting,Instance,Netmiko,我试图让我的程序从开关上查看日志,看看是否有“words”字样出现在日志中 从交换机中提取日志的部分可以工作,但检查坏词的部分不能工作。 我能够使代码适用于txt文件,但不能用于输出 我的代码: net_connect.enable() output = net_connect.send_command('show log') print(output) filename = ('log_files/SW_'+ip_addresses[count]+'_'+TNO

我试图让我的程序从开关上查看日志,看看是否有“words”字样出现在日志中

从交换机中提取日志的部分可以工作,但检查坏词的部分不能工作。 我能够使代码适用于txt文件,但不能用于输出

我的代码:

    net_connect.enable()
    output = net_connect.send_command('show log')
    print(output)
    filename = ('log_files/SW_'+ip_addresses[count]+'_'+TNOW+'.txt')

    SAVE_FILE = open(filename, 'w+')
    SAVE_FILE.write(output)

    print(filename)
    textring = (output)

    with textring as infile:
        text = infile.read()
    words = ['flapping', 'Unexpected', 'down']
    for word in words:
        if word in text:
            print('success')
            with open('warnings/SW_WARNING.txt', 'w+') as save_file:
                save_file.write(text)
            break
这是我得到的错误:

    Traceback (most recent call last):
    File "script.py", line 150, in <module>
    with textring as infile:
    AttributeError: __enter__
回溯(最近一次呼叫最后一次):
文件“script.py”,第150行,在
使用文本字符串作为填充:
AttributeError:\u输入__
有人知道如何让代码查看开关的输出,因为它还没有变成文件吗?

这里有一个错误:“使用文本字符串作为填充”(即,您缺少“打开”)。是的!:)工作就像一个魅力,感谢你花时间帮助男人,欣赏它。
# Eliminate as unnecessary/error on your "with" statement
# textring = (output)
# with textring as infile:
#    text = infile.read()

for word in ['flapping', 'Unexpected', 'down']:
    if word in output:
        print('success')
        with open('warnings/SW_WARNING.txt', 'w+') as save_file:
            save_file.write(output)
        break