Nornir and Regex Help

This is my code in Noir to filter the Switch Ethernet interfaces using Regex:

from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_config,netmiko_send_command,netmiko_save_config
from nornir_utils.plugins.functions import print_result
import re
from jinja2 import Environment, FileSystemLoader
import csv

nr = InitNornir(“config.yaml”)

output = nr.run(netmiko_send_command, command_string = ‘show ip int brief’)

print_result(output)

regex = re.findall(r"Ethernet\d+\W[1-3]", output)

print(regex)

When I compile the script and I’m getting the below error:

Traceback (most recent call last): File "/Users/kranthikumar/PycharmProjects/Noinr/nornir_test.py", line 14, in regex = re.findall(r"Ethernet\d+\W[1-3]", output) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/re.py", line 239, in findall return _compile(pattern, flags).findall(string) TypeError: expected string or bytes-like object netmiko_send_command************************************************************ * Switches ** changed : False ************************************************** vvvv netmiko_send_command ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO Interface IP-Address OK? Method Status Protocol Ethernet0/0 unassigned YES unset up up Ethernet0/1 unassigned YES unset up up Ethernet0/2 unassigned YES unset up up Ethernet0/3 unassigned YES unset up up Vlan10 172.16.219.30 YES NVRAM up up ^^^^ END netmiko_send_command ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Process finished with exit code 1

If I use the same regex formula using Netmiko Library & it works fine. Could someone please help me with what I’m doing wrong?

Try this:

out = ‘’
for key in result.keys():
out += result[key][1].result # 获取第一个task结果
regex = re.findall(r"Ethernet\d+\W[1-3]", out)
print(regex)

Hi- Thanks for getting back to me.

I will try it and let you know if it works. Also, please LMK of what these commands does?

Thanks