question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

textfsm.parser.TextFSMError: State Error raised.

See original GitHub issue

Simple script to show vlans on an HP switch using Netmiko with TextFSM.

from netmiko import Netmiko
from netmiko import ConnectHandler
from getpass import getpass

password = getpass("Enter password: ")
net_conn = ConnectHandler(device_type='hp_procurve', ip='172.16.1.1', username='admin', password=password)

output = net_conn.send_command("show vlans", use_textfsm=True)
print(output)

When I run this I get the following output

(arubatest) [16:19:45] dvarnum:arubaos $ python aruba-ipv6-fhs.py
Traceback (most recent call last):
  File "aruba-ipv6-fhs.py", line 21, in <module>
    output = net_conn.send_command("show vlans", use_textfsm=True)
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/netmiko/base_connection.py", line 1340, in send_command
    output, platform=self.device_type, command=command_string.strip()
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/netmiko/utilities.py", line 268, in get_structured_data
    textfsm_obj.ParseCmd(raw_output, attrs)
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/netmiko/_textfsm/_clitable.py", line 272, in ParseCmd
    self.table = self._ParseCmdItem(self.raw, template_file=template_files[0])
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/netmiko/_textfsm/_clitable.py", line 303, in _ParseCmdItem
    for record in fsm.ParseText(cmd_input):
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/textfsm/parser.py", line 895, in ParseText
    self._CheckLine(line)
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/textfsm/parser.py", line 944, in _CheckLine
    if self._Operations(rule, line):
  File "/Users/dvarnum/.virtualenvs/arubatest/lib/python3.7/site-packages/textfsm/parser.py", line 1025, in _Operations
    % (rule.line_num, line))
textfsm.parser.TextFSMError: State Error raised. Rule Line: 13. Input Line:  

If I execute without using TextFSM I get the correct data back from the device:

(arubatest) [16:52:59] dvarnum:arubaos $ python aruba-ipv6-fhs.py     

 Status and Counters - VLAN Information

  Maximum VLANs to support : 256                  
  Primary VLAN : DEFAULT_VLAN    
  Management VLAN :                 

  VLAN ID Name                             | Status     Voice Jumbo
  ------- -------------------------------- + ---------- ----- -----
  1       DEFAULT_VLAN                     | Port-based No    No   
  198      internet-transit                 | Port-based No    No   
  199      oob-mgmt-new                     | Port-based No    No   
  1300     vlan300                          | Port-based No    No   
  1999     testing                          | Port-based No    No   
  2100    mgmt                             | Port-based No    Yes  
  3018    p2p_ln_ipv6                      | Port-based No    Yes  
 

Here is the ntc-template:

Value VLAN_ID (\d+)
Value NAME (.*?)
Value STATUS (\S+)
Value VOICE (Yes|No)
Value JUMBO (Yes|No)

Start
  ^.*VLAN ID -> VLAN

VLAN
  ^\s+${VLAN_ID}\s+${NAME}\s+(\|\s+|)${STATUS}\s+${VOICE}(\s+${JUMBO}|)\s*$$ -> Record
  ^\s+-+\s+-+\s+(\+\s+|)-+\s+-+(\s+-+|)\s*$$
  ^.*$$ -> Error

If I use this template in a separate textfsm file without Netmiko, it works:

import io
import textfsm

template = io.StringIO("""\
Value VLAN_ID (\d+)
Value NAME (.*?)
Value STATUS (\S+)
Value VOICE (Yes|No)
Value JUMBO (Yes|No)

Start
  ^.*VLAN ID -> VLAN

VLAN
  ^\s+${VLAN_ID}\s+${NAME}\s+(\|\s+|)${STATUS}\s+${VOICE}(\s+${JUMBO}|)\s*$$ -> Record
  ^\s+-+\s+-+\s+(\+\s+|)-+\s+-+(\s+-+|)\s*$$
  ^.*$$ -> Error
""")

fsm = textfsm.TextFSM(template)
result = fsm.ParseText("""\
 Status and Counters - VLAN Information

  Maximum VLANs to support : 256                  
  Primary VLAN : DEFAULT_VLAN    
  Management VLAN :                 

  VLAN ID Name                             | Status     Voice Jumbo
  ------- -------------------------------- + ---------- ----- -----
  1       DEFAULT_VLAN                     | Port-based No    No   
  198      internet-transit                 | Port-based No    No   
  199      oob-mgmt-new                     | Port-based No    No   
  1999     testing                          | Port-based No    No   
  2100    mgmt                             | Port-based No    Yes  
  3018    p2p_ln_ipv6                      | Port-based No    Yes  
""")

print(result)

Output:

(arubatest) [16:57:47] dvarnum:arubaos $ python textfsm_testing.py
['1', 'DEFAULT_VLAN', 'Port-based', 'No', 'No']
['198', 'internet-transit', 'Port-based', 'No', 'No']
['199', 'oob-mgmt-new', 'Port-based', 'No', 'No']
['1999', 'testing', 'Port-based', 'No', 'No']
['2100', 'mgmt', 'Port-based', 'No', 'Yes']
['2018', 'p2p_ln_ipv6', 'Port-based', 'No', 'Yes']

Note that Netmiko with TextFSM indeed works for other commands on hp_procurve, just failing with this one and I can’t figure out why, especially since it works with using textfsm directly. Any ideas if this is a Netmiko-related issue or something else?

(arubatest) [16:58:15] dvarnum:arubaos $ pip freeze
asn1crypto==0.24.0
bcrypt==3.1.7
cffi==1.12.3
cryptography==2.7
future==0.17.1
Jinja2==2.10.1
MarkupSafe==1.1.1
netmiko==2.4.1
paramiko==2.6.0
pycparser==2.19
PyNaCl==1.3.0
pyserial==3.4
scp==0.13.2
six==1.12.0
textfsm==1.1.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Jul 31, 2019

Probably should feed that back into ntc-templates if you can.

1reaction
varnumdcommented, Jul 31, 2019

Wow, you were spot-on - that did the trick! Thank you for taking the time to help me on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

textfsm.parser.TextFSMError: State Error raised
I am scripting to find any BGP issue from multiple devices with Nornir using "TextFSM". The python with nornir works correctly without "TextFSM....
Read more >
How to use the textfsm.parser.TextFSMTemplateError ...
Parse (line) except TextFSMTemplateError as error: raise TextFSMTemplateError('%s Line %s.' % (error, self._line_num)) if value.name in self.header: raise ...
Read more >
textfsm.parser.TextFSMError: State Error raised ...
Simple script to show interfaces status on an cisco switch using Netmiko with TextFSM. from netmiko import Netmiko from netmiko import ...
Read more >
ntc-templates 1.5.0
Repository of TextFSM Templates for Network Devices, ... textfsm.parser.TextFSMError: State Error raised. ... Cisco IOS - textfsm.parser.
Read more >
ntc-templates Changelog - pyup.io
Cisco IOS - textfsm.parser.TextFSMError: State Error raised. Rule Line: 17. [\718](https://github.com/networktocode/ntc-templates/issues/718)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found