napalm-automation-community / napalm-h3c-cw7-ssh

NAPALM driver for H3C Comware V7, over SSH
Apache License 2.0
22 stars 9 forks source link

Charmap Codec Can't Decode Byte #2

Open DatalinkNetworks opened 1 year ago

DatalinkNetworks commented 1 year ago

Hi there,

I have a switch stack of S5820X devices which should be compatible with the S5500 series of devices.

Running a simple .get_facts() on the system results in a UnicodeDecodeError with the following traceback:

Traceback (most recent call last):

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\threading.py", line 966, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x000001E764F16710>
    └ <Thread(ThreadPoolExecutor-0_0, started 57100)>

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x000001E764F16440>
    └ <Thread(ThreadPoolExecutor-0_0, started 57100)>

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(ThreadPoolExecutor-0_0, started 57100)>
    │    │        │    └ (<weakref at 0x000001E769A1E070; to 'ThreadPoolExecutor' at 0x000001E769A28670>, <_queue.SimpleQueue object at 0x000001E769A1...
    │    │        └ <Thread(ThreadPoolExecutor-0_0, started 57100)>
    │    └ <function _worker at 0x000001E764F38430>
    └ <Thread(ThreadPoolExecutor-0_0, started 57100)>

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\concurrent\futures\thread.py", line 83, in _worker
    work_item.run()
    │         └ <function _WorkItem.run at 0x000001E764F38550>
    └ <concurrent.futures.thread._WorkItem object at 0x000001E769A28940>

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             │    │   │    │       │    └ {}
             │    │   │    │       └ <concurrent.futures.thread._WorkItem object at 0x000001E769A28940>
             │    │   │    └ (HealthCheck(group='carm', name='core', host='172.16.10.1', port=22, username='redacted', password='redacted', driver='h3c...
             │    │   └ <concurrent.futures.thread._WorkItem object at 0x000001E769A28940>
             │    └ <function HealthCheck.run at 0x000001E7694A83A0>
             └ <concurrent.futures.thread._WorkItem object at 0x000001E769A28940>

> File "D:\Programming\Python\healthcheck\healthcheck\job.py", line 54, in run
    if (value := self._run()) is None:
                 │    └ <function HealthCheck._run at 0x000001E7694A8700>
                 └ HealthCheck(group='carm', name='core', host='172.16.10.1', port=22, username='redacted', password='redacted', driver='h3c_...

  File "D:\Programming\Python\healthcheck\healthcheck\job.py", line 91, in _run
    facts = device.get_facts()
            │      └ <function ComwareDriver.get_facts at 0x000001E769A5CD30>
            └ <napalm_h3c_comware.comware.ComwareDriver object at 0x000001E7699F3910>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\napalm_h3c_comware\comware.py", line 120, in get_facts
    structured_int_info = self._get_structured_output("display interface")
                          │    └ <function ComwareDriver._get_structured_output at 0x000001E769A5CCA0>
                          └ <napalm_h3c_comware.comware.ComwareDriver object at 0x000001E7699F3910>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\napalm_h3c_comware\comware.py", line 88, in _get_structured_output
    result = textfsm_extractor(self, template_name, raw_output)
             │                 │     │              └ ' Bridge-Aggregation1 current state: UP\n IP Packet Frame Type: PKTFMT_ETHNT_2, Hardware Address: 3ce5-a678-4bfe\n Descriptio...
             │                 │     └ 'display_interface'
             │                 └ <napalm_h3c_comware.comware.ComwareDriver object at 0x000001E7699F3910>
             └ <function textfsm_extractor at 0x000001E768C7EC20>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\napalm\base\helpers.py", line 284, in textfsm_extractor
    fsm_handler = textfsm.TextFSM(f)
                  │       │       └ <_io.TextIOWrapper name='D:\\Programming\\Python\\healthcheck\\.venv\\lib\\site-packages\\napalm_h3c_comware/utils/textfsm_te...     
                  │       └ <class 'textfsm.parser.TextFSM'>
                  └ <module 'textfsm' from 'D:\\Programming\\Python\\healthcheck\\.venv\\lib\\site-packages\\textfsm\\__init__.py'>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\textfsm\parser.py", line 586, in __init__
    self._Parse(template)
    │    │      └ <_io.TextIOWrapper name='D:\\Programming\\Python\\healthcheck\\.venv\\lib\\site-packages\\napalm_h3c_comware/utils/textfsm_te...
    │    └ <function TextFSM._Parse at 0x000001E768313250>
    └ <textfsm.parser.TextFSM object at 0x000001E769A67B80>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\textfsm\parser.py", line 684, in _Parse
    self._ParseFSMVariables(template)
    │    │                  └ <_io.TextIOWrapper name='D:\\Programming\\Python\\healthcheck\\.venv\\lib\\site-packages\\napalm_h3c_comware/utils/textfsm_te...
    │    └ <function TextFSM._ParseFSMVariables at 0x000001E7683132E0>
    └ <textfsm.parser.TextFSM object at 0x000001E769A67B80>

  File "D:\Programming\Python\healthcheck\.venv\lib\site-packages\textfsm\parser.py", line 708, in _ParseFSMVariables
    for line in template:
                └ <_io.TextIOWrapper name='D:\\Programming\\Python\\healthcheck\\.venv\\lib\\site-packages\\napalm_h3c_comware/utils/textfsm_te...

  File "C:\Users\aarch\.pyenv\pyenv-win\versions\3.10.4\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           │      │              │     │    │      └ '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !...
           │      │              │     │    └ 'strict'
           │      │              │     └ <encodings.cp1252.IncrementalDecoder object at 0x000001E769A66170>
           │      │              └ b'Value Required INTERFACE (\\S+)\nValue LINK_STATUS (.+)\nValue PROTOCOL_STATUS (\\S+)\nValue MAC_ADDRESS (\\S+)\nValue DESC...      
           │      └ <built-in function charmap_decode>
           └ <module 'codecs' from 'C:\\Users\\aarch\\.pyenv\\pyenv-win\\versions\\3.10.4\\lib\\codecs.py'>

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 406: character maps to <undefined>

Attached is the precise value of raw_output when printed to a file: 105463-1042167.734.txt

mmjahad commented 1 year ago

Hello,

I also got the same exact error with the same traceback :

Traceback (most recent call last):
  File "C:\Users\[REDACTED]\Documents\Development\Console Automation\extract_ssh_configuration.py", line 83, in <module>
    main()
  File "C:\Users\[REDACTED]\Documents\Development\Console Automation\extract_ssh_configuration.py", line 48, in main
    switch_facts = device.get_facts()
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\napalm_h3c_comware\comware.py", line 118, in get_facts
    structured_int_info = self._get_structured_output("display interface")
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\napalm_h3c_comware\comware.py", line 86, in _get_structured_output
    result = textfsm_extractor(self, template_name, raw_output)
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\napalm\base\helpers.py", line 284, in textfsm_extractor
    fsm_handler = textfsm.TextFSM(f)
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\textfsm\parser.py", line 586, in __init__
    self._Parse(template)
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\textfsm\parser.py", line 684, in _Parse
    self._ParseFSMVariables(template)
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\site-packages\textfsm\parser.py", line 708, in _ParseFSMVariables
    for line in template:
  File "C:\Users\[REDACTED]\Documents\Portable Python-3.10.5 x64\App\Python\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 406: character maps to <undefined>

I tried to use the netmiko arg encoding but with no change :

netmiko_args = {  'encoding' : 'utf-8' }
device = driver(sw_host, sw_user, sw_password, timeout=30, optional_args=netmiko_args)